Search in sources :

Example 1 with TypeSignature

use of org.apache.druid.segment.column.TypeSignature in project druid by druid-io.

the class ObjectWriter method writeHeader.

static void writeHeader(final JsonGenerator jsonGenerator, final RelDataType rowType, final boolean includeTypes, final boolean includeSqlTypes) throws IOException {
    final RowSignature signature = RowSignatures.fromRelDataType(rowType.getFieldNames(), rowType);
    jsonGenerator.writeStartObject();
    for (int i = 0; i < signature.size(); i++) {
        jsonGenerator.writeFieldName(signature.getColumnName(i));
        if (!includeTypes && !includeSqlTypes) {
            jsonGenerator.writeNull();
        } else {
            jsonGenerator.writeStartObject();
            if (includeTypes) {
                jsonGenerator.writeStringField(ObjectWriter.TYPE_HEADER_NAME, signature.getColumnType(i).map(TypeSignature::asTypeString).orElse(null));
            }
            if (includeSqlTypes) {
                jsonGenerator.writeStringField(ObjectWriter.SQL_TYPE_HEADER_NAME, rowType.getFieldList().get(i).getType().getSqlTypeName().getName());
            }
            jsonGenerator.writeEndObject();
        }
    }
    jsonGenerator.writeEndObject();
}
Also used : TypeSignature(org.apache.druid.segment.column.TypeSignature) RowSignature(org.apache.druid.segment.column.RowSignature)

Example 2 with TypeSignature

use of org.apache.druid.segment.column.TypeSignature in project druid by druid-io.

the class CsvWriter method writeHeader.

@Override
public void writeHeader(final RelDataType rowType, final boolean includeTypes, final boolean includeSqlTypes) {
    final RowSignature signature = RowSignatures.fromRelDataType(rowType.getFieldNames(), rowType);
    writer.writeNext(signature.getColumnNames().toArray(new String[0]), false);
    if (includeTypes) {
        final String[] types = new String[rowType.getFieldCount()];
        for (int i = 0; i < signature.size(); i++) {
            types[i] = signature.getColumnType(i).map(TypeSignature::asTypeString).orElse(null);
        }
        writer.writeNext(types, false);
    }
    if (includeSqlTypes) {
        final String[] sqlTypes = new String[rowType.getFieldCount()];
        for (int i = 0; i < signature.size(); i++) {
            sqlTypes[i] = rowType.getFieldList().get(i).getType().getSqlTypeName().getName();
        }
        writer.writeNext(sqlTypes, false);
    }
}
Also used : TypeSignature(org.apache.druid.segment.column.TypeSignature) RowSignature(org.apache.druid.segment.column.RowSignature)

Example 3 with TypeSignature

use of org.apache.druid.segment.column.TypeSignature in project druid by druid-io.

the class ArrayWriter method writeHeader.

static void writeHeader(final JsonGenerator jsonGenerator, final RelDataType rowType, final boolean includeTypes, final boolean includeSqlTypes) throws IOException {
    final RowSignature signature = RowSignatures.fromRelDataType(rowType.getFieldNames(), rowType);
    jsonGenerator.writeStartArray();
    for (String columnName : signature.getColumnNames()) {
        jsonGenerator.writeString(columnName);
    }
    jsonGenerator.writeEndArray();
    if (includeTypes) {
        jsonGenerator.writeStartArray();
        for (int i = 0; i < signature.size(); i++) {
            jsonGenerator.writeString(signature.getColumnType(i).map(TypeSignature::asTypeString).orElse(null));
        }
        jsonGenerator.writeEndArray();
    }
    if (includeSqlTypes) {
        jsonGenerator.writeStartArray();
        for (int i = 0; i < signature.size(); i++) {
            jsonGenerator.writeString(rowType.getFieldList().get(i).getType().getSqlTypeName().getName());
        }
        jsonGenerator.writeEndArray();
    }
}
Also used : TypeSignature(org.apache.druid.segment.column.TypeSignature) RowSignature(org.apache.druid.segment.column.RowSignature)

Aggregations

RowSignature (org.apache.druid.segment.column.RowSignature)3 TypeSignature (org.apache.druid.segment.column.TypeSignature)3