spark jdbc api 无法使用内置函数
spark jdbc api can't use built-in function
我想从 impala table 获取子查询作为一个数据集。
代码如下:
String subQuery = "(select to_timestamp(unix_timestamp(now())) as ts from my_table) t"
Dataset<Row> ds = spark.read().jdbc(myImpalaUrl, subQuery, prop);
但是结果是错误的:
Caused by: java.sql.SQLDataException: [Cloudera][JDBC](10140) Error converting value to Timestamp.
我可以使用unix_timestamp
功能,但是to_timestmap
失败了,为什么?
我发现 org.apache.spark.sql.execution.datasources.jdbc.JDBC.compute()
中的代码存在一些问题:
sqlText = s"SELECT $columnList FROM ${options.table} $myWhereClause"
$columList
包含 "
之类的 "col_name"
,当我删除 "
时它工作正常。
我通过添加方言解决了这个问题,默认方言会在列名中添加""
,
JdbcDialect ImpalaDialect = new JdbcDialect(){
@Override
public boolean canHandle(String url) {
return url.startsWith("jdbc:impala") || url.contains("impala");
}
@Override
public String quoteIdentifier(String colName) {
return colName;
}
};
JdbcDialects.registerDialect(ImpalaDialect);
我想从 impala table 获取子查询作为一个数据集。
代码如下:
String subQuery = "(select to_timestamp(unix_timestamp(now())) as ts from my_table) t"
Dataset<Row> ds = spark.read().jdbc(myImpalaUrl, subQuery, prop);
但是结果是错误的:
Caused by: java.sql.SQLDataException: [Cloudera][JDBC](10140) Error converting value to Timestamp.
我可以使用unix_timestamp
功能,但是to_timestmap
失败了,为什么?
我发现 org.apache.spark.sql.execution.datasources.jdbc.JDBC.compute()
中的代码存在一些问题:
sqlText = s"SELECT $columnList FROM ${options.table} $myWhereClause"
$columList
包含 "
之类的 "col_name"
,当我删除 "
时它工作正常。
我通过添加方言解决了这个问题,默认方言会在列名中添加""
,
JdbcDialect ImpalaDialect = new JdbcDialect(){
@Override
public boolean canHandle(String url) {
return url.startsWith("jdbc:impala") || url.contains("impala");
}
@Override
public String quoteIdentifier(String colName) {
return colName;
}
};
JdbcDialects.registerDialect(ImpalaDialect);