本文整理汇总了Scala中org.apache.spark.sql.catalyst.expressions.Literal类的典型用法代码示例。如果您正苦于以下问题:Scala Literal类的具体用法?Scala Literal怎么用?Scala Literal使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Literal类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: extractPartitionValues
//设置package包名称以及导入依赖的类
package org.apache.spark.sql.execution.datasources
import com.google.code.regexp.Pattern
import org.apache.hadoop.fs.Path
import org.apache.spark.sql.catalyst.expressions.Literal
import com.paypal.risk.spark.pigloader.PartitionValues
import org.apache.spark.sql.types.StringType
import scala.collection.JavaConverters._
Literal.create(raw, StringType)
//Literal(raw, StringType)
}
def extractPartitionValues(pattern: String, path: Path): PartitionValues = {
val pathName = path.toString
//old way
//val (columnNames, values) = (pattern.split("/").tail zip pathName.split("/").tail).filter(pair => !pair._1.equals(pair._2)).filter(pair => isPattern(pair._1) && matchPartPattern(pair._1, pair._2)).map(pair => (extractPatternKey(pair._1), inferPartitionColumnValue(extractPatternVaule(pair._1, pair._2)))).unzip
//new way
val p = Pattern.compile(pattern)
val m = p.matcher(pathName)
val (columnNames, values) = m.namedGroups().asScala.map(kv => (kv._1,inferPartitionColumnValue(kv._2))).toSeq.unzip
PartitionValues(columnNames.map(_.toLowerCase), values)
}
def resolvePartitions(pathsWithPartitionValues: Seq[(Path, PartitionValues)]):
Seq[PartitionValues]= {
val input = pathsWithPartitionValues.map(values =>
(values._1, org.apache.spark.sql.execution.datasources.PartitioningUtils.PartitionValues(values._2.columnNames, values._2.literals)))
val result = org.apache.spark.sql.execution.datasources.PartitioningUtils.resolvePartitions(input)
result.map(t => PartitionValues(t.columnNames, t.literals))
}
}