本文整理汇总了Scala中org.apache.spark.sql.types.LongType类的典型用法代码示例。如果您正苦于以下问题:Scala LongType类的具体用法?Scala LongType怎么用?Scala LongType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LongType类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: ColumnsTest
//设置package包名称以及导入依赖的类
package com.drakeconsulting.big_data_maker
import org.scalatest.FunSuite
import com.holdenkarau.spark.testing.SharedSparkContext
import org.apache.spark.sql.SQLContext
import org.apache.spark.sql.types.{StructField, StringType, LongType, DoubleType}
class ColumnsTest extends FunSuite with SharedSparkContext {
val numLoops = 100
test("test StringConstant") {
val s1 = new StringConstant("f1", "abc")
assert("abc" === s1.getValue(1))
assert(StructField("f1", StringType, false) == s1.getStructField)
}
test("test RandomLong") {
val s1 = new RandomLong("f1", 666666L)
for (x <- 1 to numLoops) {
assert(s1.getValue(1) >= 0)
assert(s1.getValue(1) <= 666666L)
}
assert(StructField("f1", LongType, false) == s1.getStructField)
}
test("test RandomDouble") {
val s1 = new RandomDouble("f1", 666666.00)
for (x <- 1 to numLoops) {
assert(s1.getValue(1) >= 0)
assert(s1.getValue(1) <= 666666.00)
}
assert(StructField("f1", DoubleType, false) == s1.getStructField)
}
test("test Categorical") {
val list = List("a", "b", "c", "d")
val s1 = new Categorical("f1", list)
for (x <- 1 to numLoops) {
val v = s1.getValue(1)
assert(list.exists(key => v.contains(key)))
}
assert(StructField("f1", StringType, false) == s1.getStructField)
}
}
示例2: NaiveOrderResolutionTest
//设置package包名称以及导入依赖的类
package by.skaryna.rules
import org.apache.spark.sql.catalyst.plans.logical.{LogicalPlan, Project, Sort}
import org.apache.spark.sql.{DataFrame, SparkSession}
import org.apache.spark.sql.functions._
import org.apache.spark.sql.types.LongType
import org.scalatest.{BeforeAndAfter, FlatSpec}
class NaiveOrderResolutionTest extends FlatSpec with BeforeAndAfter {
private var spark: SparkSession = _
before {
spark = SparkSession.builder.
master("local[*]")
.withExtensions(extensions => extensions.injectOptimizerRule(session => NaiveOrderResolution))
.config("spark.ui.enabled", "false")
.getOrCreate()
}
after {
if (spark != null) {
spark.stop()
}
}
"NaiveOrderResolution" should "avoid unnecessary sorting" in {
val df = generateDataFrame(10)
val sorted = df.sort("key")
val renamed = sorted.withColumnRenamed("key", "key2")
val sortedAgain = renamed.sort("key2")
assert(checkOptimizedPlan(sortedAgain.queryExecution.optimizedPlan))
}
private def checkOptimizedPlan(logicalPlan: LogicalPlan): Boolean = logicalPlan match {
case Sort(_, _, Project(_, Project(_, _))) => true
case _ => false
}
private def generateDataFrame(cnt: Int): DataFrame = {
val ids = spark.sqlContext.range(0, cnt)
ids.withColumn("key", (rand() * 1000000).cast(LongType))
}
}
示例3: TestMetadataConstructor
//设置package包名称以及导入依赖的类
package com.springml.spark.salesforce.metadata
import org.apache.spark.sql.types.{StructType, StringType, IntegerType, LongType,
FloatType, DateType, TimestampType, BooleanType, StructField}
import org.scalatest.FunSuite
import com.springml.spark.salesforce.Utils
class TestMetadataConstructor extends FunSuite {
test("Test Metadata generation") {
val columnNames = List("c1", "c2", "c3", "c4")
val columnStruct = columnNames.map(colName => StructField(colName, StringType, true))
val schema = StructType(columnStruct)
val schemaString = MetadataConstructor.generateMetaString(schema,"sampleDataSet", Utils.metadataConfig(null))
assert(schemaString.length > 0)
assert(schemaString.contains("sampleDataSet"))
}
test("Test Metadata generation With Custom MetadataConfig") {
val columnNames = List("c1", "c2", "c3", "c4")
val intField = StructField("intCol", IntegerType, true)
val longField = StructField("longCol", LongType, true)
val floatField = StructField("floatCol", FloatType, true)
val dateField = StructField("dateCol", DateType, true)
val timestampField = StructField("timestampCol", TimestampType, true)
val stringField = StructField("stringCol", StringType, true)
val someTypeField = StructField("someTypeCol", BooleanType, true)
val columnStruct = Array[StructField] (intField, longField, floatField, dateField, timestampField, stringField, someTypeField)
val schema = StructType(columnStruct)
var metadataConfig = Map("string" -> Map("wave_type" -> "Text"))
metadataConfig += ("integer" -> Map("wave_type" -> "Numeric", "precision" -> "10", "scale" -> "0", "defaultValue" -> "100"))
metadataConfig += ("float" -> Map("wave_type" -> "Numeric", "precision" -> "10", "scale" -> "2"))
metadataConfig += ("long" -> Map("wave_type" -> "Numeric", "precision" -> "18", "scale" -> "0"))
metadataConfig += ("date" -> Map("wave_type" -> "Date", "format" -> "yyyy/MM/dd"))
metadataConfig += ("timestamp" -> Map("wave_type" -> "Date", "format" -> "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"))
val schemaString = MetadataConstructor.generateMetaString(schema, "sampleDataSet", metadataConfig)
assert(schemaString.length > 0)
assert(schemaString.contains("sampleDataSet"))
assert(schemaString.contains("Numeric"))
assert(schemaString.contains("precision"))
assert(schemaString.contains("scale"))
assert(schemaString.contains("18"))
assert(schemaString.contains("Text"))
assert(schemaString.contains("Date"))
assert(schemaString.contains("format"))
assert(schemaString.contains("defaultValue"))
assert(schemaString.contains("100"))
assert(schemaString.contains("yyyy/MM/dd"))
assert(schemaString.contains("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"))
}
}
示例4: SqlShiftMySQLDialect
//设置package包名称以及导入依赖的类
package com.goibibo.sqlshift.commons
import java.sql.Types
import org.apache.spark.sql.jdbc.{JdbcDialect, JdbcDialects}
import org.apache.spark.sql.types.{DataType, IntegerType, LongType, MetadataBuilder}
case object SqlShiftMySQLDialect extends JdbcDialect {
override def canHandle(url: String): Boolean = url.startsWith("jdbc:mysql")
override def getCatalystType(sqlType: Int, typeName: String, size: Int, md: MetadataBuilder): Option[DataType] = {
if (sqlType == Types.VARBINARY && typeName.equals("BIT") && size != 1) {
// This could instead be a BinaryType if we'd rather return bit-vectors of up to 64 bits as
// byte arrays instead of longs.
md.putLong("binarylong", 1)
Option(LongType)
} else if (typeName.equals("TINYINT")) {
Option(IntegerType)
} else None
}
override def quoteIdentifier(colName: String): String = {
s"`$colName`"
}
override def getTableExistsQuery(table: String): String = {
s"SELECT 1 FROM $table LIMIT 1"
}
def registerDialect(): Unit = {
}
}