Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache spark 当我们试图将Spark数据帧写入Cassandra时,Cassandra类型如何在内部强制转换数据类型?_Apache Spark_Cassandra_Apache Spark Sql_Spark Cassandra Connector - Fatal编程技术网

Apache spark 当我们试图将Spark数据帧写入Cassandra时,Cassandra类型如何在内部强制转换数据类型?

Apache spark 当我们试图将Spark数据帧写入Cassandra时,Cassandra类型如何在内部强制转换数据类型?,apache-spark,cassandra,apache-spark-sql,spark-cassandra-connector,Apache Spark,Cassandra,Apache Spark Sql,Spark Cassandra Connector,为了提供关于这个问题的更多见解,当我们试图在Cassandra中向整数列写入字符串时,Cassandra如何在内部类型转换或将此字符串输入设想为整数 卡桑德拉模式: CREATE TABLE keyspace_name.table_name1 ( col1 text, col2 int, col3 text, col4 text PRIMARY KEY (col1) 数据帧架构: root |-- col1: string (nullable = true)

为了提供关于这个问题的更多见解,当我们试图在Cassandra中向整数列写入字符串时,Cassandra如何在内部类型转换或将此字符串输入设想为整数

卡桑德拉模式:

CREATE TABLE keyspace_name.table_name1 (
    col1 text,
    col2 int,
    col3 text,
    col4 text PRIMARY KEY (col1)
数据帧架构:

root
 |-- col1: string (nullable = true)
 |-- col2: string (nullable = true)
 |-- col3: string (nullable = true)
 |-- col4: string (nullable = true)

这是通过注册不同CQL类型的类型转换器来完成的。例如,为中的
int
类型定义了以下代码:

此代码使用generic
convert
,将特定于类型的函数实现的实际转换卸载到部分函数
convertPF
。对于能够从
数字
或从
字符串
转换为整数的:

def convertPF = {
  case x: Number => x.intValue
  case x: String => x.toInt
}

您可以寻找其他的实现,例如,CQL
date
可以从不同的类型获得-string、long、UUID、…

感谢您的更新!现在,我对此有了一些基本的了解。
def convertPF = {
  case x: Number => x.intValue
  case x: String => x.toInt
}