在Clojure中,我可以这样做:
(-> path
clojure.java.io/resource
slurp
read-string)
Run Code Online (Sandbox Code Playgroud)
而不是这样做:
(read-string (slurp (clojure.java.io/resource path)))
Run Code Online (Sandbox Code Playgroud)
这在Clojure术语中称为线程 ,有助于摆脱许多括号.
在Python中,如果我尝试使用像map,的函数结构any,或者filter我必须将它们相互嵌套.在Python中是否有一个构造,我可以在Clojure中做类似于线程化(或管道化)的操作?
我不是在寻找功能齐全的版本,因为Python中没有宏,我只是想在Python中进行函数式编程时取消大量的括号.
编辑:我最终使用支持ing的toolzpipe.
我正在尝试编写一个返回复杂类型的 UDF:
private val toPrice = UDF1<String, Map<String, String>> { s ->
val elements = s.split(" ")
mapOf("value" to elements[0], "currency" to elements[1])
}
val type = DataTypes.createStructType(listOf(
DataTypes.createStructField("value", DataTypes.StringType, false),
DataTypes.createStructField("currency", DataTypes.StringType, false)))
df.sqlContext().udf().register("toPrice", toPrice, type)
Run Code Online (Sandbox Code Playgroud)
但任何时候我使用这个:
df = df.withColumn("price", callUDF("toPrice", col("price")))
Run Code Online (Sandbox Code Playgroud)
我收到一个神秘的错误:
private val toPrice = UDF1<String, Map<String, String>> { s ->
val elements = s.split(" ")
mapOf("value" to elements[0], "currency" to elements[1])
}
val type = DataTypes.createStructType(listOf(
DataTypes.createStructField("value", DataTypes.StringType, false),
DataTypes.createStructField("currency", DataTypes.StringType, false)))
df.sqlContext().udf().register("toPrice", toPrice, type)
Run Code Online (Sandbox Code Playgroud)
我尝试使用自定义数据类型: …
我在src/main/resources文件夹(RobotoMono.ttf)中向项目添加了自定义字体。然后我尝试从CSS文件中加载它,如下所示:
@font-face {
font-family: 'RobotoMono';
src: url('RobotoMono.ttf');
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试将此字体设置为某种字体时,它不起作用:
.column-header-label {
-fx-label-padding: 0;
-fx-text-overrun: clip;
-fx-font-family: 'RobotoMono';
}
Run Code Online (Sandbox Code Playgroud)
如果我将字体设置为系统上存在的某种字体,则可以看到字体发生了变化,但是我包含的字体不起作用。
我究竟做错了什么?
我想从 Java 使用 GitHub 的 GraphQL API,经过大量搜索后,我找不到一个库或其他解决方案,可以让我以一种易于使用的方式做到这一点。
官方文档也没有详细说明如何做到这一点。
如何使用 GitHub 的 v4 API?我想根据 API 本身生成代码,以便我可以以编程方式使用它。
我正在将镶木地板文件从 Databricks 加载到 Spark:
val dataset = context.session.read().parquet(parquetPath)
Run Code Online (Sandbox Code Playgroud)
然后我执行一些像这样的转换:
val df = dataset.withColumn(
columnName, concat_ws("",
col(data.columnName), lit(textToAppend)))
Run Code Online (Sandbox Code Playgroud)
当我尝试将其作为 JSON 保存到 Kafka 时(而不是返回到 parquet!):
df = df.select(
lit("databricks").alias("source"),
struct("*").alias("data"))
val server = "kafka.dev.server" // some url
df = dataset.selectExpr("to_json(struct(*)) AS value")
df.write()
.format("kafka")
.option("kafka.bootstrap.servers", server)
.option("topic", topic)
.save()
Run Code Online (Sandbox Code Playgroud)
我得到以下异常:
org.apache.spark.sql.execution.QueryExecutionException: Parquet column cannot be converted in file dbfs:/mnt/warehouse/part-00001-tid-4198727867000085490-1e0230e7-7ebc-4e79-9985-0a131bdabee2-4-c000.snappy.parquet. Column: [item_group_id], Expected: StringType, Found: INT32
at org.apache.spark.sql.execution.datasources.FileScanRDD$$anon$1$$anonfun$prepareNextFile$1.apply(FileScanRDD.scala:310)
at org.apache.spark.sql.execution.datasources.FileScanRDD$$anon$1$$anonfun$prepareNextFile$1.apply(FileScanRDD.scala:287)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at …Run Code Online (Sandbox Code Playgroud) apache-spark ×2
java ×2
apache-kafka ×1
css ×1
databricks ×1
fonts ×1
github ×1
github-api ×1
graphql ×1
javafx ×1
kotlin ×1
parquet ×1
python ×1
scala ×1