由于列不匹配,将 spark 数据帧插入 phoenix table 时遇到问题

Facing issues while inserting spark dataframe to phoenix table due to column mismatch

我正在创建一个具有以下结构的凤凰table

CREATE TABLE IF NOT EXISTS "TEST1"(
"slhdr" VARCHAR(100),
    "totmins" INTEGER,
    "totslrcds" INTEGER,
 "tottime" INTEGER,   CONSTRAINT pk PRIMARY KEY ("sleepelement")
);

现在,我通过从另一个数据框中选择特定的列,从 JSON 数据创建了一个数据框。以下是此数据框的架构:

newDF.printSchema

root
 |-- slhdr: array (nullable = true)
 |    |-- element: string (containsNull = true)
 |-- totmins: long (nullable = true)
 |-- totslrcds: long (nullable = true)
 |-- tottime: long (nullable = true)

现在我尝试在以下代码的帮助下使用此数据框将数据插入到凤凰 table 上方:

 newDF.write 
          .format("org.apache.phoenix.spark") 
          .mode("overwrite") 
          .option("table", "TEST1") 
          .option("zkUrl", "Server details") 
          .save()

但是它无法将数据框列映射到 table 列,我收到以下错误:

Caused by: org.apache.spark.SparkException: Job aborted due to stage failure: Task 33 in stage 74.0 failed 4 times, most recent failure: Lost task 33.3 in stage 74.0 (TID 2663, ailab003.incedoinc.com, executor 2): java.sql.SQLException: Unable to resolve these column names:
SLHDR,TOTMINS,TOTSLRCDS,TOTTIME
Available columns with column families:
slhdr,0.totmins,0.totslrcds,0.tottime

看起来 phoenix table 正在为我不理解的最后 3 列创建默认列族“0”。

有没有办法插入这些数据。

我在一份 'phoenix' 文档中读到,目标 table 和源 'dataframe' 中的列名称应该完全相同,并且它们也区分大小写。我意识到我的 table 列是小写的,而 'dataframe' 列是大写的。我重新创建了我的 table 和 'dataframe' 都具有大写的列名称,如下所示:

CREATE TABLE IF NOT EXISTS "TEST1"(
"SLHDR" VARCHAR(100),
    "TOTMINS" INTEGER,
    "TOTSLRCDS" INTEGER,
 "TOTTIME" INTEGER,   CONSTRAINT pk PRIMARY KEY ("sleepelement")
);

newDF.printSchema

root
 |-- SLHDR: array (nullable = true)
 |    |-- element: string (containsNull = true)
 |-- TOTMINS: long (nullable = true)
 |-- TOTSLRCDS: long (nullable = true)
 |-- TOTTIME: long (nullable = true)

一旦我这样做了,这个数据就成功地插入了我的凤凰 table 使用相同的代码:

 newDF.write 
          .format("org.apache.phoenix.spark") 
          .mode("overwrite") 
          .option("table", "TEST1") 
          .option("zkUrl", "Server details") 
          .save()