0
点赞
收藏
分享

微信扫一扫

scala match的运用

you的日常 2023-04-11 阅读 57


单个变量

var clusterManager: Int = arg match {
            case "yarn" => YARN
            case "yarn-client" | "yarn-cluster" =>
                println(s"Master ${arg} is deprecated since 2.0." +
                    " Please use master \"yarn\" with specified deploy mode instead.")
                YARN
            case m if m.startsWith("spark") => STANDALONE
            case m if m.startsWith("mesos") => MESOS
            case m if m.startsWith("local") => LOCAL
            case _ =>
                println("Master must either be yarn or start with spark, mesos, local")
                -1
        }

多个变量

(args.master, args.deployMode) match {
        case ("yarn-cluster", null) =>
          deployMode = CLUSTER
          args.master = "yarn"
        case ("yarn-cluster", "client") =>
          printErrorAndExit("Client deploy mode is not compatible with master \"yarn-cluster\"")
        case ("yarn-client", "cluster") =>
          printErrorAndExit("Cluster deploy mode is not compatible with master \"yarn-client\"")
        case (_, mode) =>
          args.master = "yarn"
      }


举报

相关推荐

0 条评论