Java Code Examples for org.apache.spark.sql.types.TimestampType

The following examples show how to use org.apache.spark.sql.types.TimestampType. These examples are extracted from open source projects. 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 Project: indexr   Source File:    License: Apache License 2.0 6 votes vote down vote up
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(, type, isIndexed.apply(;
    return new SegmentSchema(columns);
Example 2
Source Project: indexr   Source File:    License: Apache License 2.0 5 votes vote down vote up
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;
            case BIGINT:
                dataType = DataTypes.LongType;
            case FLOAT:
                dataType = DataTypes.FloatType;
            case DOUBLE:
                dataType = DataTypes.DoubleType;
            case VARCHAR:
                dataType = DataTypes.StringType;
            case DATE:
                dataType = DataTypes.DateType;
            case DATETIME:
                dataType = DataTypes.TimestampType;
                throw new IllegalStateException("Unsupported type: " + cs.getSqlType());
        fields.add(new StructField(cs.getName(), dataType,, Metadata.empty()));
    return fields;
Example 3
Source Project: bunsen   Source File:    License: Apache License 2.0 4 votes vote down vote up
public void instantToTimestamp() {
  Assert.assertTrue(getField(observationSchema, true, "issued") instanceof TimestampType);