scala match的运用

单个变量

        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"
      }
发布了919 篇原创文章 · 获赞 167 · 访问量 176万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览