使用ksqlDB连接流和表

时间:2020-10-07 13:15:58

标签: apache-kafka ksqldb

我正在尝试加入以下KSQL表:

CREATE TABLE devices
    ("current" STRUCT<
        "device" VARCHAR, 
        "group" VARCHAR, 
        "inventoryState" VARCHAR, 
        "location" STRUCT<
            "geo" STRUCT<
                "latitude" DOUBLE, 
                "longitude" DOUBLE>, 
            "address" STRUCT<
                "city" VARCHAR, 
                "postalCode" VARCHAR, 
                "street" VARCHAR, 
                "houseNumber" VARCHAR, 
                "floor" VARCHAR, 
                "company" VARCHAR, 
                "country" VARCHAR, 
                "reference" VARCHAR, 
                "timeZone" VARCHAR, 
                "region" VARCHAR, 
                "district" VARCHAR>
            >
        >)
WITH (KAFKA_TOPIC='device', VALUE_FORMAT='JSON');

...具有以下KSQL流:

CREATE STREAM "events" (
    "device" VARCHAR,
    "event" VARCHAR,
    "firstOccurenceTime" VARCHAR,
    "lastOccurenceTime" VARCHAR,
    "occurenceCount" INTEGER,
    "receiveTime" VARCHAR,
    "persistTime" VARCHAR,
    "state" VARCHAR,
    "context" MAP < VARCHAR, VARCHAR >) 
WITH (KAFKA_TOPIC = 'device-event', VALUE_FORMAT = 'JSON');

...将location结构包含到新流(enriched_events)中。

这是我正在测试新流的KSQL select语句:

SELECT devices."current"->"device" AS "device",
    devices."current"->"location" AS "location",
    "event",
    "firstOccurenceTime",
    "lastOccurenceTime",
    "receiveTime",
    "persistTime",
    "state",
    "context"
FROM "events"
INNER JOIN devices ON "events".ROWKEY = devices.ROWKEY
EMIT CHANGES;

即使将auto.offset.reset设置为earliest,我也没有任何数据回来。

我检查了device表和device-event流是否都填充了数据。


我在做什么错了?


更新

devices表的示例数据(由于公司政策而删除了敏感值):

{
  "persistTime" : "2020-10-12T11:48:23.384Z",
  "previous" : {
    "device" : "REDACTED",
    "type" : "REDACTED",
    "group" : "REDACTED",
    "inventoryState" : "unknown",
    "managementState" : "connected",
    "communicationId" : "REDACTED",
    "manufacturer" : "",
    "description" : "",
    "model" : "",
    "location" : {
      "geo" : {
        "latitude" : "REDACTED",
        "longitude" : "REDACTED"
      },
      "address" : {
        "city" : "",
        "postalCode" : "",
        "street" : "",
        "houseNumber" : "",
        "floor" : "",
        "company" : "",
        "country" : "",
        "reference" : "",
        "timeZone" : "",
        "region" : "",
        "district" : ""
      },
      "logicalInstallationPoint" : ""
    },
    "tags" : [ ]
  },
  "current" : {
    "device" : "REDACTED",
    "type" : "REDACTED",
    "group" : "REDACTED",
    "inventoryState" : "unknown",
    "managementState" : "connected",
    "communicationId" : "REDACTED",
    "manufacturer" : "",
    "description" : "",
    "model" : "",
    "location" : {
      "geo" : {
        "latitude" : "REDACTED",
        "longitude" : "REDACTED"
      },
      "address" : {
        "city" : "",
        "postalCode" : "",
        "street" : "",
        "houseNumber" : "",
        "floor" : "",
        "company" : "",
        "country" : "",
        "reference" : "",
        "timeZone" : "",
        "region" : "",
        "district" : ""
      },
      "logicalInstallationPoint" : ""
    },
    "tags" : [ ]
  }
}

0 个答案:

没有答案