我正在尝试从 cassandra 获取 ttl 列,但到目前为止我无法使其工作。
这是我迄今为止尝试过的:
SparkSession sparkSession = SparkSession.builder()
.appName("Spark Sql Job").master("local[*]")
.config("spark.sql.warehouse.dir", "file:///c:/tmp/spark-warehouse")
.config("spark.cassandra.connection.host", "localhost")
.config("spark.cassandra.connection.port", "9042")
.getOrCreate();
SQLContext sqlCtx = sparkSession.sqlContext();
Dataset<Row> rowsDataset = sqlCtx.read()
.format("org.apache.spark.sql.cassandra")
.option("keyspace", "myschema")
.option("table", "mytable").load();
rowsDataset.createOrReplaceTempView("xyz");
rowsDataset = sparkSession.sql("select ttl(emp_phone) from vouchers");
rowsDataset.show();
最佳答案
来自 Spark-cassandra-connector 文档:
The select method allows querying for TTL and timestamp of the table cell.
Example Using Select to Retreive TTL and Timestamp
val row = rdd.select("column", "column".ttl, "column".writeTime).first
val ttl = row.getLong("ttl(column)")
val timestamp = row.getLong("writetime(column)")
The selected columns can be given aliases by calling as on the column selector, which is particularly handy when fetching TTLs and timestamps.
https://github.com/datastax/spark-cassandra-connector/blob/master/doc/3_selection.md
关于java - Spark从cassandra获取ttl列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55259169/