我在Scala和Python中编写了以下代码,但是返回的DataFrame似乎并未应用我正在应用的架构中的非可空字段.italianVotes.csv是一个csv文件,带有'〜'作为分隔符和四个字段.我正在使用Spark 2.1.0.
2657~135~2~2013-11-22 00:00:00.0
2658~142~2~2013-11-22 00:00:00.0
2659~142~1~2013-11-22 00:00:00.0
2660~140~2~2013-11-22 00:00:00.0
2661~140~1~2013-11-22 00:00:00.0
2662~1354~2~2013-11-22 00:00:00.0
2663~1356~2~2013-11-22 00:00:00.0
2664~1353~2~2013-11-22 00:00:00.0
2665~1351~2~2013-11-22 00:00:00.0
2667~1357~2~2013-11-22 00:00:00.0
Run Code Online (Sandbox Code Playgroud)
import org.apache.spark.sql.types._
val schema = StructType(
StructField("id", IntegerType, false) ::
StructField("postId", IntegerType, false) ::
StructField("voteType", IntegerType, true) ::
StructField("time", TimestampType, true) :: Nil)
val fileName = "italianVotes.csv"
val italianDF = spark.read.schema(schema).option("sep", "~").csv(fileName)
italianDF.printSchema()
// output
root
|-- id: integer (nullable = true)
|-- postId: integer (nullable = true)
|-- voteType: integer (nullable = …Run Code Online (Sandbox Code Playgroud) 我无法在气流使用的dag目录之外移动公共代码.我查看了气流源并找到了imp.load_source.
是否可以使用imp.load_source加载dag目录之外的模块?在下面的示例中,这将从公共目录导入foo或bar.
?? airflow_home
|???? dags
? ??? dag_1.py
? ??? dag_2.py
??? common
??? foo.py
??? bar.py
Run Code Online (Sandbox Code Playgroud)