• 【数据mock】大数据Mock商城数据


    前言

    为方便大家学习大数据过程中,需要数据进行练习与调试,本次给大家分享几篇mock数据的脚本

    可适用于kafka;hive;spark;flink;presto;clickhouse等等框架的操作练习

    • kafka 数据mock
    • hive 数据mock
    • presto 数据mock
    • spark 数据mock
    • flink 数据mock
    • clickhouse 数据mock
    • doris 数据mock

    mock数据脚本-基础版

        private static void mock(String brokers, String topic) {
            String[] versions = new String[]{"V1.2.0", "V1.2.1", "V1.2.2"};
            String[] channels = new String[]{"小米商城", "华为商城", "AppStore"};
            String[] netTypes = new String[]{"WiFi", "4G", "5G"};
            String[] var10000 = new String[]{"cart", "browse", "pay"};
            String[] deviceTypes = new String[]{"小米11 Ultra", "iPhone 11", "iPhone 10", "iPhone 9", "华为V65"};
            Map devices = new HashMap();
            devices.put("小米11 Ultra", "Android");
            devices.put("iPhone 11", "iOS");
            devices.put("iPhone 10", "iOS");
            devices.put("iPhone 9", "iOS");
            devices.put("华为V65", "Android");
            List categories = new ArrayList();
            categories.add("Hadoop系统入门核心精讲 大数据实战");
            categories.add("SparkSQL极速入门整合Kudu实现广告业务数据分析 大数据实战");
            categories.add("Spark进阶大数据离线与实时项目实战 大数据实战");
            categories.add("学习Scala进击大数据Spark生态圈 大数据实战");
            categories.add("实战Spark3实时处理掌握两套企业级处理方案 大数据实战");
            categories.add("辣条 食品饮料");
            categories.add("矿泉水 食品饮料");
            categories.add("咖啡 食品饮料");
            categories.add("茅子 食品饮料");
            categories.add("五子 食品饮料");
            categories.add("宝马 车");
            categories.add("奔驰 车");
            categories.add("奥迪 车");
            categories.add("保时捷 车");
            categories.add("法拉利 车");
            categories.add("冲锋衣 户外");
            categories.add("帆布鞋 户外");
            categories.add("跑步鞋 户外");
            categories.add("山地车 户外");
            categories.add("运动包 户外");
    
            for (int i = 100; i <= 1000; ++i) {
                Access access = new Access();
                access.setUid("user_" + i);
                access.setVersion(versions[(new Random()).nextInt(versions.length)]);
                access.setDevice(UUID.randomUUID().toString());
                access.setEvent("startup");
                String deviceType = deviceTypes[(new Random()).nextInt(deviceTypes.length)];
                access.setDeviceType(deviceType);
                access.setOs((String) devices.get(deviceType));
                access.setNet(netTypes[(new Random()).nextInt(netTypes.length)]);
                String ip = getRandomIp();
                access.setIp(ip);
                access.setChannel(channels[(new Random()).nextInt(channels.length)]);
                access.setTime(System.currentTimeMillis() + 107200000000L + 86400000L);
                if (i % 3 != 0) {
                    access.setNu(1);
                }
                else {
                    access.setNu(0);
                }
    
                String info = JSON.toJSON(access).toString();
                System.out.println(info);
                Thread.sleep(1000L);
            }
        }
    
    
        private static String getRandomIp() {
            int[][] range = new int[][]{{607649792, 608174079}, {1038614528, 1039007743}, {1783627776, 1784676351}, {2035023872, 2035154943}, {2078801920, 2079064063}, {-1950089216, -1948778497}, {-1425539072, -1425014785}, {-1236271104, -1235419137}, {-770113536, -768606209}, {-569376768, -564133889}};
            Random rdint = new Random();
            int index = rdint.nextInt(10);
            String ip = num2ip(range[index][0] + (new Random()).nextInt(range[index][1] - range[index][0]));
            return ip;
        }
    
        private static String num2ip(int ip) {
            int[] b = new int[4];
            String x = "";
            b[0] = ip >> 24 & 255;
            b[1] = ip >> 16 & 255;
            b[2] = ip >> 8 & 255;
            b[3] = ip & 255;
            x = Integer.toString(b[0]) + "." + Integer.toString(b[1]) + "." + Integer.toString(b[2]) + "." + Integer.toString(b[3]);
            return x;
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80

    mock 数据截取如下:

    {"deviceType":"iPhone 10","uid":"user_1","product":{"name":"矿泉水","category":"食品饮料"},"os":"iOS","ip":"106.82.37.76","nu":1,"channel":"小米商城","time":1754026686804,"event":"cart","net":"4G","device":"4e0b3735-9f86-4b6b-a8e6-bc328a4135b8","version":"V1.2.1"}
    {"deviceType":"iPhone 10","uid":"user_1","product":{"name":"实战Spark3实时处理掌握两套企业级处理方案","category":"大数据实战"},"os":"iOS","ip":"106.82.37.76","nu":1,"channel":"小米商城","time":1754026686804,"event":"browse","net":"4G","device":"4e0b3735-9f86-4b6b-a8e6-bc328a4135b8","version":"V1.2.1"}
    {"deviceType":"iPhone 10","uid":"user_1","product":{"name":"宝马","category":"车"},"os":"iOS","ip":"106.82.37.76","nu":1,"channel":"小米商城","time":1754026686804,"event":"pay","net":"4G","device":"4e0b3735-9f86-4b6b-a8e6-bc328a4135b8","version":"V1.2.1"}
    {"deviceType":"iPhone 10","uid":"user_1","product":{"name":"法拉利","category":"车"},"os":"iOS","ip":"106.82.37.76","nu":1,"channel":"小米商城","time":1754026686804,"event":"browse","net":"4G","device":"4e0b3735-9f86-4b6b-a8e6-bc328a4135b8","version":"V1.2.1"}
    
    
    • 1
    • 2
    • 3
    • 4
    • 5

    mock数据-集成到kafka

      private static KafkaProducer sendKafka(String brokers) {
            Properties properties = new Properties();
            properties.put("bootstrap.servers", brokers);
            properties.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
            properties.put("acks", "1");
            properties.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
            return new KafkaProducer(properties);
        }
    
    
        private static void mock(String brokers, String topic) {
            KafkaProducer producer = sendKafka("broker");
    
            String[] versions = new String[]{"V1.2.0", "V1.2.1", "V1.2.2"};
            String[] channels = new String[]{"小米商城", "华为商城", "AppStore"};
            String[] netTypes = new String[]{"WiFi", "4G", "5G"};
            String[] var10000 = new String[]{"cart", "browse", "pay"};
            String[] deviceTypes = new String[]{"小米11 Ultra", "iPhone 11", "iPhone 10", "iPhone 9", "华为V65"};
            Map devices = new HashMap();
            devices.put("小米11 Ultra", "Android");
            devices.put("iPhone 11", "iOS");
            devices.put("iPhone 10", "iOS");
            devices.put("iPhone 9", "iOS");
            devices.put("华为V65", "Android");
            List categories = new ArrayList();
            categories.add("Hadoop系统入门核心精讲 大数据实战");
            categories.add("SparkSQL极速入门整合Kudu实现广告业务数据分析 大数据实战");
            categories.add("Spark进阶大数据离线与实时项目实战 大数据实战");
            categories.add("学习Scala进击大数据Spark生态圈 大数据实战");
            categories.add("实战Spark3实时处理掌握两套企业级处理方案 大数据实战");
            categories.add("辣条 食品饮料");
            categories.add("矿泉水 食品饮料");
            categories.add("咖啡 食品饮料");
            categories.add("茅子 食品饮料");
            categories.add("五子 食品饮料");
            categories.add("宝马 车");
            categories.add("奔驰 车");
            categories.add("奥迪 车");
            categories.add("保时捷 车");
            categories.add("法拉利 车");
            categories.add("冲锋衣 户外");
            categories.add("帆布鞋 户外");
            categories.add("跑步鞋 户外");
            categories.add("山地车 户外");
            categories.add("运动包 户外");
    
            for (int i = 100; i <= 1000; ++i) {
                Access access = new Access();
                access.setUid("user_" + i);
                access.setVersion(versions[(new Random()).nextInt(versions.length)]);
                access.setDevice(UUID.randomUUID().toString());
                access.setEvent("startup");
                String deviceType = deviceTypes[(new Random()).nextInt(deviceTypes.length)];
                access.setDeviceType(deviceType);
                access.setOs((String) devices.get(deviceType));
                access.setNet(netTypes[(new Random()).nextInt(netTypes.length)]);
                String ip = getRandomIp();
                access.setIp(ip);
                access.setChannel(channels[(new Random()).nextInt(channels.length)]);
                access.setTime(System.currentTimeMillis() + 107200000000L + 86400000L);
                if (i % 3 != 0) {
                    access.setNu(1);
                }
                else {
                    access.setNu(0);
                }
    
                String info = JSON.toJSON(access).toString();
                System.out.println(info);
                producer.send(new ProducerRecord(topic, info));
                Thread.sleep(1000L);
            }
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
  • 相关阅读:
    ureport内置数据源(多个源) + dynamic-datasource-spring-boot-starter
    lenovo联想笔记本ThinkPad系列T15p或P15v Gen3(21DA,21DB,21D8,21D9)原厂Win11系统镜像
    FlowDroid安装初体验
    无监督学习KMeans学习笔记和实例
    供应 JOSEF约瑟 跳位合位监视继电器 JZ-7GJ-S002XMC AC220V
    深入理解Java中的线程安全List:CopyOnWriteArrayList原理和应用
    《2022谷歌开发者大会》参会之旅
    【iMessage苹果推群发】软件安装利用dropbox分享外链进行访问原始文件
    SpringBoot源码解读与原理分析(三十六)SpringBoot整合WebMvc(一)@Controller控制器装配原理
    mac版Idea快捷键
  • 原文地址:https://blog.csdn.net/qq_31557939/article/details/126053490