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();
}
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);
}
}
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();
}
}
Aggregations