【问题标题】:cassandra uuid in SELECT statements with Spark SQL使用 Spark SQL 的 SELECT 语句中的 cassandra uuid
【发布时间】:2016-02-20 02:57:43
【问题描述】:

我在 cassandra (v. 2.2.3) 中有下表

cqlsh> DESCRIBE TABLE historian.timelines;

CREATE TABLE historian.timelines (
    assetid uuid,
    tslice int,
    ...
    value map<text, text>,
    PRIMARY KEY ((assetid, tslice), ...)
) WITH CLUSTERING ORDER BY (deviceid ASC, paramid ASC, fts DESC) 
...
    ;

我想通过 Apache Spark (v. 1.5.0) 通过以下 java sn-p 提取数据(使用 cassandra spark connector v. 1.5.0 和 cassandra driver core v. 2.2.0 RC3):

// Initialize Spark SQL Context
CassandraSQLContext sqlContext = new CassandraSQLContext(jsc.sc());
sqlContext.setKeyspace(keyspace);
DataFrame df = sqlContext.sql("SELECT * FROM " + tableName + 
    " WHERE assetid = '085eb9c6-8a16-11e5-af63-feff819cdc9f' LIMIT 2");
df.show();

此时访问上述show 方法时出现以下错误:

cannot resolve '(assetid = cast(085eb9c6-8a16-11e5-af63-feff819cdc9f as double))' due to data type mismatch: 
differing types in '(assetid = cast(085eb9c6-8a16-11e5-af63-feff819cdc9f as double))' (uuid and double).;

因此,Spark SQL 似乎没有将 assetid 输入解释为 UUID。我可以做些什么来处理 Spark SQL 查询中的 cassandra UUID 类型?

谢谢!

【问题讨论】:

    标签: apache-spark cassandra


    【解决方案1】:

    确实,您的查询参数是字符串而不是 UUID,只需像这样转换查询参数:

    import java.util.UUID;
    
    DataFrame df = sqlContext.sql("SELECT * FROM " + tableName + 
    " WHERE assetid = "+ UUID.fromString("085eb9c6-8a16-11e5-af63-feff819cdc9f") +" LIMIT 2");
    

    【讨论】:

      猜你喜欢
      • 2019-03-09
      • 2014-12-05
      • 2013-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-03
      • 2019-03-18
      相关资源
      最近更新 更多