当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


R SparkR dropFields用法及代码示例


说明:

按名称删除结构Column 中的字段。

用法:

dropFields(x, ...)

## S4 method for signature 'Column'
dropFields(x, ...)

参数:

  • x 一列
  • ... 要删除的字段的名称。

注意:

从 3.1.0 开始的 dropFields

例子:

df <- select(
  createDataFrame(iris),
  alias(
    struct(
      column("Sepal_Width"), column("Sepal_Length"),
      alias(
        struct(
          column("Petal_Width"), column("Petal_Length"),
          alias(
            column("Petal_Width") * column("Petal_Length"),
            "Petal_Product"
          )
        ),
        "Petal"
      )
    ),
    "dimensions"
  )
)
head(withColumn(df, "dimensions", dropFields(df$dimensions, "Petal")))

head(
  withColumn(
    df, "dimensions",
    dropFields(df$dimensions, "Sepal_Width", "Sepal_Length")
  )
)

# This method supports dropping multiple nested fields directly e.g.
head(
  withColumn(
    df, "dimensions",
    dropFields(df$dimensions, "Petal.Petal_Width", "Petal.Petal_Length")
  )
)

# However, if you are going to add/replace multiple nested fields,
# it is preferred to extract out the nested struct before
# adding/replacing multiple fields e.g.
head(
  withColumn(
    df, "dimensions",
    withField(
      column("dimensions"),
      "Petal",
      dropFields(column("dimensions.Petal"), "Petal_Width", "Petal_Length")
    )
  )
)

相关用法


注:本文由纯净天空筛选整理自spark.apache.org大神的英文原创作品 dropFields。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。