use of org.apache.drill.common.types.TypeProtos.MinorType in project drill by apache.
the class UnionReaderImpl method rebindMemberNullState.
/**
* Rebind the null state reader to include the union's own state.
*/
private void rebindMemberNullState() {
for (int i = 0; i < variants.length; i++) {
AbstractObjectReader objReader = variants[i];
if (objReader == null) {
continue;
}
NullStateReader nullReader;
MinorType type = MinorType.values()[i];
switch(type) {
case DICT:
case MAP:
case LIST:
nullReader = new NullStateReaders.ComplexMemberStateReader(typeReader, type);
break;
default:
nullReader = new NullStateReaders.MemberNullStateReader(nullStateReader, objReader.events().nullStateReader());
}
objReader.events().bindNullState(nullReader);
}
}
use of org.apache.drill.common.types.TypeProtos.MinorType in project drill by apache.
the class ColumnWriterFactory method newWriter.
public static BaseScalarWriter newWriter(ValueVector vector) {
final MajorType major = vector.getField().getType();
final MinorType type = major.getMinorType();
try {
final Class<? extends BaseScalarWriter> accessorClass = requiredWriters[type.ordinal()];
if (accessorClass == null) {
throw new UnsupportedOperationException(type.toString());
}
final Constructor<? extends BaseScalarWriter> ctor = accessorClass.getConstructor(ValueVector.class);
return ctor.newInstance(vector);
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | SecurityException | IllegalArgumentException | InvocationTargetException e) {
throw new IllegalStateException(e);
}
}
use of org.apache.drill.common.types.TypeProtos.MinorType in project drill by apache.
the class JsonWriter method writeValue.
private void writeValue(FieldReader reader) throws JsonGenerationException, IOException {
final DataMode m = reader.getType().getMode();
final MinorType mt = reader.getType().getMinorType();
switch(m) {
case OPTIONAL:
case REQUIRED:
switch(mt) {
case FLOAT4:
gen.writeFloat(reader);
break;
case FLOAT8:
gen.writeDouble(reader);
break;
case INT:
gen.writeInt(reader);
break;
case SMALLINT:
gen.writeSmallInt(reader);
break;
case TINYINT:
gen.writeTinyInt(reader);
break;
case BIGINT:
gen.writeBigInt(reader);
break;
case BIT:
gen.writeBoolean(reader);
break;
case DATE:
gen.writeDate(reader);
break;
case TIME:
gen.writeTime(reader);
break;
case TIMESTAMP:
gen.writeTimestamp(reader);
break;
case INTERVALYEAR:
case INTERVALDAY:
case INTERVAL:
gen.writeInterval(reader);
break;
case DECIMAL28DENSE:
case DECIMAL28SPARSE:
case DECIMAL38DENSE:
case DECIMAL38SPARSE:
case DECIMAL9:
case DECIMAL18:
case VARDECIMAL:
gen.writeDecimal(reader);
break;
case LIST:
// this is a pseudo class, doesn't actually contain the real reader so we have to drop down.
gen.writeStartArray();
while (reader.next()) {
writeValue(reader.reader());
}
gen.writeEndArray();
break;
case MAP:
gen.writeStartObject();
if (reader.isSet()) {
for (String name : reader) {
FieldReader childReader = reader.reader(name);
if (childReader.isSet()) {
gen.writeFieldName(name);
writeValue(childReader);
}
}
}
gen.writeEndObject();
break;
case NULL:
case LATE:
gen.writeUntypedNull();
break;
case VAR16CHAR:
gen.writeVar16Char(reader);
break;
case VARBINARY:
gen.writeBinary(reader);
break;
case VARCHAR:
gen.writeVarChar(reader);
break;
}
break;
case REPEATED:
gen.writeStartArray();
switch(mt) {
case FLOAT4:
for (int i = 0; i < reader.size(); i++) {
gen.writeFloat(i, reader);
}
break;
case FLOAT8:
for (int i = 0; i < reader.size(); i++) {
gen.writeDouble(i, reader);
}
break;
case INT:
for (int i = 0; i < reader.size(); i++) {
gen.writeInt(i, reader);
}
break;
case SMALLINT:
for (int i = 0; i < reader.size(); i++) {
gen.writeSmallInt(i, reader);
}
break;
case TINYINT:
for (int i = 0; i < reader.size(); i++) {
gen.writeTinyInt(i, reader);
}
break;
case BIGINT:
for (int i = 0; i < reader.size(); i++) {
gen.writeBigInt(i, reader);
}
break;
case BIT:
for (int i = 0; i < reader.size(); i++) {
gen.writeBoolean(i, reader);
}
break;
case DATE:
for (int i = 0; i < reader.size(); i++) {
gen.writeDate(i, reader);
}
break;
case TIME:
for (int i = 0; i < reader.size(); i++) {
gen.writeTime(i, reader);
}
break;
case TIMESTAMP:
for (int i = 0; i < reader.size(); i++) {
gen.writeTimestamp(i, reader);
}
break;
case INTERVALYEAR:
case INTERVALDAY:
case INTERVAL:
for (int i = 0; i < reader.size(); i++) {
gen.writeInterval(i, reader);
}
break;
case DECIMAL28DENSE:
case DECIMAL28SPARSE:
case DECIMAL38DENSE:
case DECIMAL38SPARSE:
case DECIMAL9:
case DECIMAL18:
case VARDECIMAL:
for (int i = 0; i < reader.size(); i++) {
gen.writeDecimal(i, reader);
}
break;
case LIST:
for (int i = 0; i < reader.size(); i++) {
while (reader.next()) {
writeValue(reader.reader());
}
}
break;
case MAP:
while (reader.next()) {
gen.writeStartObject();
for (String name : reader) {
FieldReader mapField = reader.reader(name);
if (mapField.isSet()) {
gen.writeFieldName(name);
writeValue(mapField);
}
}
gen.writeEndObject();
}
break;
case NULL:
break;
case VAR16CHAR:
for (int i = 0; i < reader.size(); i++) {
gen.writeVar16Char(i, reader);
}
break;
case VARBINARY:
for (int i = 0; i < reader.size(); i++) {
gen.writeBinary(i, reader);
}
break;
case VARCHAR:
for (int i = 0; i < reader.size(); i++) {
gen.writeVarChar(i, reader);
}
break;
default:
throw new IllegalStateException(String.format("Unable to handle type %s.", mt));
}
gen.writeEndArray();
break;
}
}
use of org.apache.drill.common.types.TypeProtos.MinorType in project drill by apache.
the class MapUtility method writeToMapFromReader.
public static void writeToMapFromReader(FieldReader fieldReader, MapWriter mapWriter, String fieldName, String caller) {
try {
MajorType valueMajorType = fieldReader.getType();
MinorType valueMinorType = valueMajorType.getMinorType();
WriterExtractor extractor = new WriterExtractor(fieldName, valueMajorType, mapWriter, fieldReader instanceof UnionReader);
switch(valueMinorType) {
case TINYINT:
fieldReader.copyAsValue(extractor.get(ListWriter::tinyInt, MapWriter::tinyInt, UnionVectorWriter::tinyInt));
break;
case SMALLINT:
fieldReader.copyAsValue(extractor.get(ListWriter::smallInt, MapWriter::smallInt, UnionVectorWriter::smallInt));
break;
case BIGINT:
fieldReader.copyAsValue(extractor.get(ListWriter::bigInt, MapWriter::bigInt, UnionVectorWriter::bigInt));
break;
case INT:
fieldReader.copyAsValue(extractor.get(ListWriter::integer, MapWriter::integer, UnionVectorWriter::integer));
break;
case UINT1:
fieldReader.copyAsValue(extractor.get(ListWriter::uInt1, MapWriter::uInt1, UnionVectorWriter::uInt1));
break;
case UINT2:
fieldReader.copyAsValue(extractor.get(ListWriter::uInt2, MapWriter::uInt2, UnionVectorWriter::uInt2));
break;
case UINT4:
fieldReader.copyAsValue(extractor.get(ListWriter::uInt4, MapWriter::uInt4, UnionVectorWriter::uInt4));
break;
case UINT8:
fieldReader.copyAsValue(extractor.get(ListWriter::uInt8, MapWriter::uInt8, UnionVectorWriter::uInt8));
break;
case DECIMAL9:
fieldReader.copyAsValue((Decimal9Writer) extractor.get(ListWriter::decimal9, MapWriter::decimal9, UnionVectorWriter::decimal9));
break;
case DECIMAL18:
fieldReader.copyAsValue((Decimal18Writer) extractor.get(ListWriter::decimal18, MapWriter::decimal18, UnionVectorWriter::decimal18));
break;
case DECIMAL28SPARSE:
fieldReader.copyAsValue((Decimal28SparseWriter) extractor.get(ListWriter::decimal28Sparse, MapWriter::decimal28Sparse, UnionVectorWriter::decimal28Sparse));
break;
case DECIMAL38SPARSE:
fieldReader.copyAsValue((Decimal38SparseWriter) extractor.get(ListWriter::decimal38Sparse, MapWriter::decimal38Sparse, UnionVectorWriter::decimal38Sparse));
break;
case VARDECIMAL:
fieldReader.copyAsValue((VarDecimalWriter) extractor.get(lw -> lw.varDecimal(valueMajorType.getPrecision(), valueMajorType.getScale()), (mw, fn) -> mw.varDecimal(fn, valueMajorType.getPrecision(), valueMajorType.getScale()), uw -> uw.varDecimal(valueMajorType.getPrecision(), valueMajorType.getScale())));
break;
case DATE:
fieldReader.copyAsValue(extractor.get(ListWriter::date, MapWriter::date, UnionVectorWriter::date));
break;
case TIME:
fieldReader.copyAsValue(extractor.get(ListWriter::time, MapWriter::time, UnionVectorWriter::time));
break;
case TIMESTAMP:
fieldReader.copyAsValue(extractor.get(ListWriter::timeStamp, MapWriter::timeStamp, UnionVectorWriter::timeStamp));
break;
case INTERVAL:
fieldReader.copyAsValue(extractor.get(ListWriter::interval, MapWriter::interval, UnionVectorWriter::interval));
break;
case INTERVALDAY:
fieldReader.copyAsValue(extractor.get(ListWriter::intervalDay, MapWriter::intervalDay, UnionVectorWriter::intervalDay));
break;
case INTERVALYEAR:
fieldReader.copyAsValue(extractor.get(ListWriter::intervalYear, MapWriter::intervalYear, UnionVectorWriter::intervalYear));
break;
case FLOAT4:
fieldReader.copyAsValue(extractor.get(ListWriter::float4, MapWriter::float4, UnionVectorWriter::float4));
break;
case FLOAT8:
fieldReader.copyAsValue(extractor.get(ListWriter::float8, MapWriter::float8, UnionVectorWriter::float8));
break;
case BIT:
fieldReader.copyAsValue(extractor.get(ListWriter::bit, MapWriter::bit, UnionVectorWriter::bit));
break;
case VARCHAR:
fieldReader.copyAsValue(extractor.get(ListWriter::varChar, MapWriter::varChar, UnionVectorWriter::varChar));
break;
case VARBINARY:
fieldReader.copyAsValue(extractor.get(ListWriter::varBinary, MapWriter::varBinary, UnionVectorWriter::varBinary));
break;
case MAP:
fieldReader.copyAsValue(extractor.get(ListWriter::map, MapWriter::map, UnionVectorWriter::map));
break;
case LIST:
fieldReader.copyAsValue(mapWriter.list(fieldName).list());
break;
case DICT:
fieldReader.copyAsValue(extractor.get(ListWriter::dict, MapWriter::dict, UnionVectorWriter::dict));
break;
default:
throw new DrillRuntimeException(String.format("%s does not support input of type: %s", caller, valueMinorType));
}
} catch (ClassCastException e) {
final MaterializedField field = fieldReader.getField();
throw new DrillRuntimeException(String.format(TYPE_MISMATCH_ERROR, caller, field.getName(), field.getType()));
}
}
use of org.apache.drill.common.types.TypeProtos.MinorType in project drill by apache.
the class PreparedStatementProvider method serializeColumn.
/**
* Serialize the given {@link SerializedField} into a {@link ResultColumnMetadata}.
* @param field
* @return
*/
private static ResultColumnMetadata serializeColumn(SerializedField field) {
final ResultColumnMetadata.Builder builder = ResultColumnMetadata.newBuilder();
final MajorType majorType = field.getMajorType();
final MinorType minorType = majorType.getMinorType();
/**
* Defaults to "DRILL" as drill has as only one catalog.
*/
builder.setCatalogName(InfoSchemaConstants.IS_CATALOG_NAME);
/**
* Designated column's schema name. Empty string if not applicable. Initial
* implementation defaults to empty string as we use LIMIT 0 queries to get
* the schema and schema info is lost. If we derive the schema from plan, we
* may get the right value.
*/
builder.setSchemaName("");
/**
* Designated column's table name. Not set if not applicable. Initial
* implementation defaults to empty string as we use LIMIT 0 queries to get
* the schema and table info is lost. If we derive the table from plan, we
* may get the right value.
*/
builder.setTableName("");
builder.setColumnName(field.getNamePart().getName());
/**
* Column label name for display or print purposes.
* Ex. a column named "empName" might be labeled as "Employee Name".
* Initial implementation defaults to same value as column name.
*/
builder.setLabel(field.getNamePart().getName());
/**
* Data type in string format. Value is SQL standard type.
*/
builder.setDataType(Types.getSqlTypeName(majorType));
builder.setIsNullable(majorType.getMode() == DataMode.OPTIONAL);
/**
* For numeric data, this is the maximum precision.
* For character data, this is the length in characters.
* For datetime data types, this is the length in characters of the String representation
* (assuming the maximum allowed precision of the fractional seconds component).
* For binary data, this is the length in bytes.
* For all other types 0 is returned where the column size is not applicable.
*/
builder.setPrecision(Types.getPrecision(field.getMajorType()));
/**
* Column's number of digits to right of the decimal point. 0 is returned
* for types where the scale is not applicable
*/
builder.setScale(Types.getScale(majorType));
/**
* Indicates whether values in the designated column are signed numbers.
*/
builder.setSigned(Types.isNumericType(majorType));
/**
* Maximum number of characters required to display data from the column.
*/
builder.setDisplaySize(Types.getJdbcDisplaySize(majorType));
/**
* Is the column an aliased column. Initial implementation defaults to true
* as we derive schema from LIMIT 0 query and not plan
*/
builder.setIsAliased(true);
builder.setSearchability(ColumnSearchability.ALL);
builder.setUpdatability(ColumnUpdatability.READ_ONLY);
builder.setAutoIncrement(false);
builder.setCaseSensitivity(false);
builder.setSortable(Types.isSortable(minorType));
/**
* Returns the fully-qualified name of the Java class whose instances are manufactured if the method
* ResultSet.getObject is called to retrieve a value from the column. Applicable only to JDBC clients.
*/
builder.setClassName(DRILL_TYPE_TO_JDBC_CLASSNAME.get(minorType));
builder.setIsCurrency(false);
return builder.build();
}
Aggregations