org.apache.spark.sql.types.TimestampType Java Examples
The following examples show how to use
org.apache.spark.sql.types.TimestampType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IndexRUtil.java From indexr with Apache License 2.0 | 6 votes |
public static SegmentSchema sparkSchemaToIndexRSchema(List<StructField> sparkSchema, IsIndexed isIndexed) { List<ColumnSchema> columns = new ArrayList<>(); for (StructField f : sparkSchema) { SQLType type; if (f.dataType() instanceof IntegerType) { type = SQLType.INT; } else if (f.dataType() instanceof LongType) { type = SQLType.BIGINT; } else if (f.dataType() instanceof FloatType) { type = SQLType.FLOAT; } else if (f.dataType() instanceof DoubleType) { type = SQLType.DOUBLE; } else if (f.dataType() instanceof StringType) { type = SQLType.VARCHAR; } else if (f.dataType() instanceof DateType) { type = SQLType.DATE; } else if (f.dataType() instanceof TimestampType) { type = SQLType.DATETIME; } else { throw new IllegalStateException("Unsupported type: " + f.dataType()); } columns.add(new ColumnSchema(f.name(), type, isIndexed.apply(f.name()))); } return new SegmentSchema(columns); }
Example #2
Source File: IndexRUtil.java From indexr with Apache License 2.0 | 5 votes |
public static List<StructField> indexrSchemaToSparkSchema(SegmentSchema schema) { List<StructField> fields = new ArrayList<>(); for (ColumnSchema cs : schema.getColumns()) { DataType dataType; switch (cs.getSqlType()) { case INT: dataType = DataTypes.IntegerType; break; case BIGINT: dataType = DataTypes.LongType; break; case FLOAT: dataType = DataTypes.FloatType; break; case DOUBLE: dataType = DataTypes.DoubleType; break; case VARCHAR: dataType = DataTypes.StringType; break; case DATE: dataType = DataTypes.DateType; break; case DATETIME: dataType = DataTypes.TimestampType; break; default: throw new IllegalStateException("Unsupported type: " + cs.getSqlType()); } fields.add(new StructField(cs.getName(), dataType, scala.Boolean.box(false), Metadata.empty())); } return fields; }
Example #3
Source File: SchemaConverterTest.java From bunsen with Apache License 2.0 | 4 votes |
@Test public void instantToTimestamp() { Assert.assertTrue(getField(observationSchema, true, "issued") instanceof TimestampType); }