package com.aliyun.odps.spark.examples.myUtils

import scala.collection.mutable
object ParamUtils {
  def parseArgs(args: Array[String]): mutable.HashMap[String, String] = {
    println("args size:" + args.length)

    val rst = new mutable.HashMap[String, String]() {
      override def default(key: String) = "无参数传入"
    }
    for (a <- args) {
      val key_val = a.split(":")
      if (key_val.length >= 2) {
        // 为了解决hdfs正则化路径时Array变多个的问题
        if (rst.contains(key_val(0))) {
          val value = rst.get(key_val(0)).get
          val newValue = value + "," + key_val.splitAt(1)._2.mkString(":")
          rst += (key_val(0) -> newValue)
          println(key_val(0) + ":" + newValue)
        } else {
          rst += (key_val(0) -> key_val.splitAt(1)._2.mkString(":"))
          println(key_val(0) + ":" + key_val.splitAt(1)._2.mkString(":"))
        }
      }
    }
    rst
  }

  def parseLogKey(logKey: String): Tuple7[String, String, String, String, String, String, String] = {
    val l = logKey.split(":")
    val mid = l(0)
    val videoid = l(1)
    val logtimestamp = l(2)
    val apptype = l(3)
    val pagesource_change = l(4)
    val abcode = l(5)
    val video_recommend = l(6)
    (mid, videoid, logtimestamp, apptype, pagesource_change, abcode, video_recommend)
  }
}
