[英]Azure Databricks - writing to Az SQL table
Am reading a.正在读一个。 parquet
(sourced from MySql) file into Databricks as a DataFrame and wanted to convert few column datatypes to SQL data types. parquet
(来自 MySql)文件以 DataFrame 的形式导入 Databricks,并希望将少数列数据类型转换为 SQL 数据类型。
Example :示例:
In this case want to cast columns active
and is_agent
to SQL DataType bit and write back to new data frame.在这种情况下,要将列active
和is_agent
为 SQL DataType 位并写回新数据帧。
I want to loop through all columns in the data frame and apply above cast where source column data type is Byte.我想遍历数据框中的所有列,并在源列数据类型为字节的情况下应用上述转换。
How can this be achieved using Python.如何使用 Python 来实现这一点。
Ok got this one done as好的,完成了这个
from pyspark.sql.functions import col
from pyspark.sql.types import BooleanType
df = sourceDF.withColumn("active", col("active").cast(BooleanType())).withColumn("is_agent", col("active").cast(BooleanType()))
What I want is a function where I will pass DataFrame and loop through all column and and cast column of DataType Byte to BooleanType.我想要的是一个 function ,我将在其中传递 DataFrame 并循环遍历所有列并将 DataType Byte 的列转换为 BooleanType。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.