amazon-web-services - 如何避免 AWS/Glue 目录表更改列数据类型?
问题描述
我在我的 Glue 目录中以这种方式定义了表(通过 CF):
MyTable:
Type: AWS::Glue::Table
DependsOn : RealyseCatalogDB
Properties:
CatalogId: !Ref AWS::AccountId
DatabaseName: !Ref CatalogDatabaseName
TableInput:
Name: 'customers'
Description: Some test data
TableType: EXTERNAL_TABLE
Parameters: {
"skip.header.line.count": "1",
"compressionType": "none",
"classification": "csv",
"columnsOrdered": "true",
"areColumnsQuoted": "true",
"delimiter": ",",
"typeOfData": "file"
}
StorageDescriptor:
OutputFormat: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
Columns:
- Name: id
Type: bigint
- Name: startDate
Type: date
- Name: finalNumber
Type: smallint
- Name: price
Type: int
- Name: sumIndicator
Type: tinyint
- Name: officialName
Type: string
InputFormat: org.apache.hadoop.mapred.TextInputFormat
Location: !Sub ${SomewhereS3BasePath}/MyFile.csv
SerdeInfo:
SerializationLibrary: org.apache.hadoop.hive.serde2.OpenCSVSerde
在我的 Glue/Spark 代码中,我使用以下方法从该表中读取数据:
val df = spark.glueContext.getCatalogSource(
database = "test-db",
tableName = "customers"
).getDynamicFrame().toDF()
但是类型date
, tinyint
,smallint
被转换为字符串,而不是等效的 Spark 类型DateType
:ByteType
和ShortType
。所以我被迫添加:
df
.withColumn("startDate",col("startDate").cast(DateType))
.withColumn("finalNumber",col("finalNumber").cast(ShortType))
.withColumn("sumIndicator",col("sumIndicator").cast(ByteType))
这违背了在 CF 中定义表的目的。有什么办法可以避免这种情况吗?我尝试使用具有明确定义值的非常简单的测试数据来避免“resolveChoices”情况,但仍然是同样的问题。
解决方案
推荐阅读
- android - 将数据从 StatelessWidget 传递到 StatefulWidget
- javascript - 如何在 JavaScript 中删除撇号?
- c# - 像 OnPropertyChanging 这样的 Linq 处理程序中的挂起处理
- reactjs - 是否可以使用 forEach 迭代和替换数组中的值?
- kubernetes - Pod 之间的网络策略
- mongodb - 轮询 MongoDb MongoDB 的 collection.watch() 或使用 sched.scheduler... 的更好方法是什么?
- reactjs - 按钮单击后清除文本框反应
- java - 如何在android java中引用firebase push id
- javascript - 在 NextJS 服务器上应用 --tls-min-v1.0
- javascript - 关闭甜蜜警报后无法在 javascript 中提交表单