【问题标题】:The initial data metrics is Map[String, Any], and one of the data types in Any is WrappedArray(map(),map()). How do I get a value from map初始数据度量是 Map[String, Any],Any 中的一种数据类型是 WrappedArray(map(),map())。我如何从地图中获取值
【发布时间】:2023-01-10 02:01:53
【问题描述】:

我有一些指标数据,如下所示,它是 Map[String, Any],我想从 Map 中获取数据,例如我想从指标数据中获取 non_unique -> 1。

Map(applicationId -> local-1673262860096, job_name -> dist_batch, tmst -> 1673262884352, measure_name -> duplication_measure, metrics -> WrappedArray( Map(metric_name -> total, metric_value -> 50), Map(metric_name -> duplicate, metric_value -> 1), Map(metric_name -> unique, metric_value -> 48), Map(metric_name -> non_unique, metric_value -> 1), Map(metric_name -> distinct, metric_value -> 49) ), measure_type -> Duplication, data_source -> source)

我尝试使用val metricToInvestigate= metrics.get("metrics").get,但发现metricToInvestigate变成了Any类型,但我不知道如何得到non_unique -> 1这样的输出

【问题讨论】:

    标签: scala bigdata


    【解决方案1】:

    你必须施放它:

    val metricsMap: Map[String, Int] = 
      metrics("metrics")
      .asInstanceOf[Seq[Map[String,Int]]]
      .map { m => m("metric_name") -> m("metric_value") }
      .toMap
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-10
      • 2020-03-09
      • 2015-11-10
      • 1970-01-01
      相关资源
      最近更新 更多