数据湖探索 DLI-Redis结果表:示例

时间:2024-07-01 21:07:18

示例

  • 配置“connector.table-name”参数时的table存储模式示例。
    table模式采用hash类型存储数据,与基本hash类型将表的三个字段分别作为key、hash_key、hash_value不同,table模式下的key值可以通过“connector.table-name”和“connector.key-column”两个参数设置,将表中的所有字段名作为hash_key,字段值作为hash_value写入到hash中。
    create table redisSink(
      car_id STRING,
      car_owner STRING,
      car_brand STRING,
      car_speed INT
    ) with (
      'connector.type' = 'redis',
      'connector.host' = 'xx.xx.xx.xx',
      'connector.port' = '6379',
      'connector.password' = 'xx',
      'connector.table-name'='car_info',
      'connector.key-column'='car_id'
    );
    
    insert into redisSink
      (car_id,car_owner,car_brand,car_speed)
      VALUES
      ("A1234","OwnA","A1234",30);
  • 以下示例演示“connector.data-type”为string, list, hash, set类型时的建表语句。
    • “connector.data-type”为string类型
      表为2列:第一列为key,第二列为value。
      create table redisSink(
        attr1 STRING,
        attr2 STRING
      ) with (
        'connector.type' = 'redis',
        'connector.host' = 'xx.xx.xx.xx',
        'connector.port' = '6379',
        'connector.password' = 'xx',
        'connector.data-type' = 'string'
      );
      
      insert into redisSink
        (attr1,attr2)
        VALUES
        ("car_id","A1234");
    • “connector.data-type”为list类型
      表为2列:第一列为key,第二列为value。
       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      create table redisSink(
        attr1 STRING,
        attr2 STRING
      ) with (
        'connector.type' = 'redis',
        'connector.host' = 'xx.xx.xx.xx',
        'connector.port' = '6379',
        'connector.password' = 'xx',
        'connector.data-type' = 'list'
      );
      
      insert into redisSink
        (attr1,attr2)
        VALUES
        ("car_id","A1234");
      
    • “connector.data-type”为set类型
      表为2列:第一列为key,第二列为value。
      create table redisSink(
        attr1 STRING,
        attr2 STRING
      ) with (
        'connector.type' = 'redis',
        'connector.host' = 'xx.xx.xx.xx',
        'connector.port' = '6379',
        'connector.password' = 'xx',
        'connector.data-type' = 'set'
      );
      
      insert into redisSink
        (attr1,attr2)
        VALUES
        ("car_id","A1234");
    • “connector.data-type”为hash类型
      表为3列:第一列为key,第二列为hash_key,第三列为hash_value。
      create table redisSink(
        attr1 STRING,
        attr2 STRING,
        attr3 STRING
      ) with (
        'connector.type' = 'redis',
        'connector.host' = 'xx.xx.xx.xx',
        'connector.port' = '6379',
        'connector.password' = 'xx',
        'connector.data-type' = 'hash'
      );
      
      insert into redisSink
        (attr1,attr2,attr3)
        VALUES
        ("car_info","car_id","A1234");
support.huaweicloud.com/sqlreference-dli/dli_08_0313.html