自动生成数据(自用版)

python 阿里云mysql

# mysql数据库连接版  阿里云mysql
def create_data(H_IP="127.0.0.1",user="root",passw="123456",db="test",charset="utf8"):
    try:
        conn = pymysql.connect(host=H_IP,user=user,password=passw,db=db,charset=charset)
        cursor = conn.cursor()
        print("connect success!!!")
        # ignore忽略,意思是说,mysql不支持主键相同更新
        # 欢迎使用阿里云产品 hologres,此产品是支持的嘞
        sql = "insert ignore into t1(user_id,hy_id) values(%s,%s)"
        # 10w用户  每个用户有(20,100)个好友
        for i in range(1,100):
            for j in range(random.randint(20,100)):
                col01 = "w_" + str(i)
                col02 = "w_" + str(random.randint(1,100))
                col = (col01,col02)
                cursor.execute(sql,col)
            conn.commit()
        cursor.close()
        conn.close()
    except Exception as e:
        print(e)
# 若端口号发生改变 应该添加
ip = "xxxx"
u="xxxx"
p = "xxxx"
db = "xxxx"
create_data(H_IP=ip,user=u,passw=p,db=db)

Java 阿里云kafka

使用Gson jar包 对应maven格式

<dependency>
    <groupId>com.google.code.gson</groupId>
	<artifactId>gson</artifactId>
    <version>2.10.1</version>
</dependency>
// 主要转换JSON逻辑
import com.google.gson.Gson;

public class test01 {
    public static void  main(String[] args) {
        Gson gson = new Gson();
        testData t1 = new testData("t1",5);
        System.out.println(gson.toJson(t1));
    }
    // 生成随机数据
    static class testData{
        String uName = " " ;
        int uId = 0;

        public testData(String uName, int uId) {
            this.uName = uName;
            this.uId = uId;
        }
    }
}

阿里云 faker库自动生成

faker阿里云官网
faker参数化数据获取

-- 官方示例代码
CREATE TEMPORARY TABLE subscriptions ( 
    id STRING,
    user_id INT,
    type STRING,
    start_date TIMESTAMP(3),
    end_date TIMESTAMP(3),
    payment_expiration TIMESTAMP(3),
    proc_time AS PROCTIME()
) WITH (
  'connector' = 'faker',    -- Faker 连接器仅在 VVR-4.0.12 及以上支持
  'fields.id.expression' = '#{Internet.uuid}', 
  'fields.user_id.expression' = '#{number.numberBetween ''1'',''50''}',
  'fields.type.expression'= '#{regexify ''(basic|premium|platinum){1}''}',
  'fields.start_date.expression' = '#{date.past ''30'',''DAYS''}',
  'fields.end_date.expression' = '#{date.future ''15'',''DAYS''}',
  'fields.payment_expiration.expression' = '#{date.future ''365'',''DAYS''}'
);

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值