我的cassandra表列用小写,如下所示
CREATE TABLE model_family_by_id(
model_family_id int PRIMARY KEY,
model_family text,
create_date date,
last_update_date date,
model_family_name text
);
我的数据框架构是这样的
root
|-- MODEL_FAMILY_ID: decimal(38,10) (nullable = true)
|-- MODEL_FAMILY: string (nullable = true)
|-- CREATE_DATE: timestamp (nullable = true)
|-- LAST_UPDATE_DATE: timestamp (nullable = true)
|-- MODEL_FAMILY_NAME: string (nullable = true)
因此,在插入cassandra时,我遇到了错误消息
tabException in thread "main" java.util.NoSuchElementException: Columns not found in table sample_cbd.model_family_by_id: MODEL_FAMILY_ID, MODEL_FAMILY, CREATE_DATE, LAST_UPDATE_DATE, MODEL_FAMILY_NAME
at com.datastax.spark.connector.SomeColumns.selectFrom(ColumnSelector.scala:44)
答案 0 :(得分:1)
如果我正确理解the source code,Spark Connector将列包装在双引号中,因此它们变得区分大小写,并且与CQL定义中的名称不匹配。
您需要更改DataFrame的架构-在每列上运行withColumnRenamed
,或在每列上使用select
和alias
。