scala match的运用

阅读 58

2023-04-11


单个变量

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)

0 0 举报