有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Java有没有一种不用迭代就能查询Apache Spark模式的方法?

我试图找出是否有一种方法可以直接从从行数据集派生的Spark模式中查询结构。是否有某种Java等价于Scala提供的数据帧。模式(“结构名称”)

我曾经尝试过寻找这样一个预构建函数,但我能找到的唯一方法是遍历结构列表或生成迭代器。当Scala提供了一种简单得多的操作方式时,这似乎是多余的,尤其是当我不想检查循环或找到所需结构的确切索引时

//adding the metadata to a column
final Metadata metadata = new MetadataBuilder().putLong("metadataExample", 1).build();
final Dataset<Row> dfWithColumnMetadata = df1.withColumn("column_example", df.col("column_example"), metadata);

/*now I want to find the exact Struct and its metadata without having to loop through 
an array or create an iterator. However, the array version is the easiest way I could find. 
The con here is that I need to know the exact index of the column.*/
System.out.println(dfWithColumnMetadata.schema().fields()[0].metadata().toString());

有没有办法让我得到像Scala的df一样的东西。模式(“列\示例”)。元数据()


共 (1) 个答案

  1. # 1 楼答案

    我认为你可以使用:

    dfWithColumnMetadata.schema().apply("column_example").metadata()