- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有这段代码在 scala 中运行良好:
val schema = StructType(Array(
StructField("field1", StringType, true),
StructField("field2", TimestampType, true),
StructField("field3", DoubleType, true),
StructField("field4", StringType, true),
StructField("field5", StringType, true)
))
val df = spark.read
// some options
.schema(schema)
.load(myEndpoint)
我想用 Java 做一些类似的事情。所以我的代码如下:
final StructType schema = new StructType(new StructField[] {
new StructField("field1", new StringType(), true,new Metadata()),
new StructField("field2", new TimestampType(), true,new Metadata()),
new StructField("field3", new StringType(), true,new Metadata()),
new StructField("field4", new StringType(), true,new Metadata()),
new StructField("field5", new StringType(), true,new Metadata())
});
Dataset<Row> df = spark.read()
// some options
.schema(schema)
.load(myEndpoint);
但这给了我以下错误:
Exception in thread "main" scala.MatchError: org.apache.spark.sql.types.StringType@37c5b8e8 (of class org.apache.spark.sql.types.StringType)
我的模式似乎没有任何问题,所以我真的不知道这里的问题是什么。
spark.read().load(myEndpoint).printSchema();
root
|-- field5: string (nullable = true)
|-- field2: timestamp (nullable = true)
|-- field1: string (nullable = true)
|-- field4: string (nullable = true)
|-- field3: string (nullable = true)
schema.printTreeString();
root
|-- field1: string (nullable = true)
|-- field2: timestamp (nullable = true)
|-- field3: string (nullable = true)
|-- field4: string (nullable = true)
|-- field5: string (nullable = true)
编辑:
这是一个数据示例:
spark.read().load(myEndpoint).show(false);
+---------------------------------------------------------------+-------------------+-------------+--------------+---------+
|field5 |field2 |field1 |field4 |field3 |
+---------------------------------------------------------------+-------------------+-------------+--------------+---------+
|{"fieldA":"AAA","fieldB":"BBB","fieldC":"CCC","fieldD":"DDD"} |2018-01-20 16:54:50|SOME_VALUE |SOME_VALUE |0.0 |
|{"fieldA":"AAA","fieldB":"BBB","fieldC":"CCC","fieldD":"DDD"} |2018-01-20 16:58:50|SOME_VALUE |SOME_VALUE |50.0 |
|{"fieldA":"AAA","fieldB":"BBB","fieldC":"CCC","fieldD":"DDD"} |2018-01-20 17:00:50|SOME_VALUE |SOME_VALUE |20.0 |
|{"fieldA":"AAA","fieldB":"BBB","fieldC":"CCC","fieldD":"DDD"} |2018-01-20 18:04:50|SOME_VALUE |SOME_VALUE |10.0 |
...
+---------------------------------------------------------------+-------------------+-------------+--------------+---------+
最佳答案
使用 Datatypes
类中的静态方法和字段代替构造函数在 Spark 2.3.1 中为我工作:
StructType schema = DataTypes.createStructType(new StructField[] {
DataTypes.createStructField("field1", DataTypes.StringType, true),
DataTypes.createStructField("field2", DataTypes.TimestampType, true),
DataTypes.createStructField("field3", DataTypes.StringType, true),
DataTypes.createStructField("field4", DataTypes.StringType, true),
DataTypes.createStructField("field5", DataTypes.StringType, true)
});
关于java - 星火 java : Creating a new Dataset with a given schema,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51635553/
如果我用 dataset.batch(n).prefetch(m), 将预提取m个批次或m个 sample ? 最佳答案 Dataset.prefetch(m) 转换预取其直接输入的m元素。在这种情况
根据 TensorFlow documentation 、tf.contrib.data.Dataset 类的 prefetch 和 map 方法,都有一个名为 buffer_size 的参数. 对于
我正在使用 Flink 0.10.1 的 DataSet API 编写应用程序。我可以在 Flink 中使用单个运算符获取多个收集器吗? 我想做的是如下所示: val lines = env.read
为了使用 Google Colabs TPU,我需要一个 tf.dataset.Dataset .那么如何在这样的数据集上使用数据增强? 更具体地说,到目前为止我的代码是: def get_datas
我有一个包含 2 个相关数据表(主数据表和详细信息)的数据集。我想将与我的过滤器匹配的数据(例如主数据列 A =“XXX”)复制到另一个数据集。 现在我发现这个过程需要很长时间(1k 条记录大约需要一
我正在使用 .pvd文件同时加载多个文件到 Paraviw。对于具有单个数据集的时间序列,该文件看起来像这样: 我想指定要与 a.*.vtu 一起加载的其他文件(
我听说 Google 主办(或将举办)一场网络分类竞赛,他们提供了一个大型(170k+ 文档)网站数据集,这些网站被分为多个类别(体育、计算机、科学等),我尝试环顾四周在他们的 2009 年到 201
谁能给我解释一下 DataSet.Copy() vs Dataset.Clone()也让我知道一些我们可以使用这些的场景 最佳答案 Clone 将创建一个新的空数据集,其架构(表和列)与旧数据集相同。
dataset = dataset.batch(50) dataset = dataset.prefetch(buffer_size=1) 是预取 1 个批次还是 1 个元素? 根据 tensorfl
在 Delphi 中,与 Dataset.Next 相比,使用 Dataset.Prior 是否会降低性能? 背景: 我有一个在数据集中搜索特定记录的例程。我从数据集中的最后一条记录开始,然后使用 D
我正在使用 Spark(2.0) 开发 Spark SQL,并使用 Java API 读取 CSV。 CSV 文件中有一个双引号、逗号分隔的列。例如:“Express Air,Delivery Tru
为什么要使用DataSet.BeginInit 和DataSet.EndInit? 我已经经历了official msdn documentation ,它说 Begins the initializ
我正在尝试向新的数据集 X 添加一个位于不同数据集 Y 中的数据表。如果我直接添加它,我会得到以下错误: DataTable already belongs to another DataSet. 我
我有一个表示为形状为 (num_features, num_examples) 的 NumPy 矩阵的数据集,我希望将其转换为 TensorFlow 类型 tf.Dataset。 我正在努力理解这两种
这是 question 的转发在 ai.stackexchange 中询问。由于该论坛没有太多吸引力,我想我可以在这里尝试一下机会。 我有一个特定对象的不同尺寸的图像数据集。该物体的一些图像也处于不同
我有两个数据集: main_ds = tf.data.Dataset.from_tensor_slices(list(range(1000, 1100))) backgroud_ds = tf.dat
拥有Dataset单列 json 字符串: +--------------------+ | value| +--------------------+ |{"Contex
我正在尝试解决 Azure 数据工厂中的以下场景: 我在 Azure Blob 存储中有大量文件夹。每个文件夹包含不同数量的 parquet 格式的文件。文件夹名称包含生成该文件夹中包含的数据的日期,
我正在尝试解决 Azure 数据工厂中的以下场景: 我在 Azure Blob 存储中有大量文件夹。每个文件夹包含不同数量的 parquet 格式的文件。文件夹名称包含生成该文件夹中包含的数据的日期,
我有一个顺序数据集,我可以从中创建窗口来训练 RNN。在某些情况下,我想扔掉某些 window 。但是,当我使用 dataset.window 和 dataset.filter 时,管道内部会出现一些
我是一名优秀的程序员,十分优秀!