[英]Writing data to timestreamDb from AWS Glue
我正在尝试使用粘合流并将数据写入 AWS TimestreamDB,但我很难配置 JDBC 连接。
我正在执行的步骤如下和文档链接: https://docs.aws.amazon.com/timestream/latest/developerguide/JDBC.configuring.html
这是我的代码:
url = jdbc:timestream://AccessKeyId=<myAccessKeyId>;SecretAccessKey=<mySecretAccessKey>;SessionToken=<mySessionToken>;Region=us-east-1
source_df = sparkSession.read.format("jdbc").option("url",url).option("dbtable","IoT").option("driver","software.amazon.timestream.jdbc.TimestreamDriver").load()
datasink1 = glueContext.write_dynamic_frame.from_options(frame = applymapping0, connection_type = "jdbc", connection_options = {"url":url,"driver":"software.amazon.timestream.jdbc.TimestreamDriver", database = "CovidTestDb", dbtable = "CovidTestTable"}, transformation_ctx = "datasink1")
到目前为止(2022 年 4 月),不支持使用 timestream 的 jdbc 驱动程序进行写操作(查看代码并看到一堆不支持写的异常)。 不过,可以使用胶水从时间流中读取数据。 以下步骤对我有用:
jdbc:timestream://Region=<timestream-db-region>
应该就足够了driver
和fetchsize
选项option("driver","software.amazon.timestream.jdbc.TimestreamDriver")
option("fetchsize", "100")
(根据您的需要调整 fetchsize)以下是从时间流中读取 dataframe 的完整示例:
val df = sparkSession.read.format("jdbc")
.option("url", "jdbc:timestream://Region=us-east-1")
.option("driver","software.amazon.timestream.jdbc.TimestreamDriver")
// optionally add a query to narrow the data to fetch
.option("query", "select * from db.tbl where time between ago(15m) and now()")
.option("fetchsize", "100")
.load()
df.write.format("console").save()
希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.