use of org.apache.drill.common.types.TypeProtos.MinorType in project drill by axbaretto.
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();
}
use of org.apache.drill.common.types.TypeProtos.MinorType in project drill by axbaretto.
the class TestTupleSchema method testListSchema.
@Test
public void testListSchema() {
TupleMetadata schema = new SchemaBuilder().addList("list").addType(MinorType.BIGINT).addType(MinorType.VARCHAR).resumeSchema().buildSchema();
assertEquals(1, schema.size());
ColumnMetadata col = schema.metadata(0);
assertTrue(col instanceof VariantColumnMetadata);
// Implementation shows through here: actual major
// type is (LIST, OPTIONAL) even though the metadata
// lies that this is a variant array.
assertEquals(MinorType.LIST, col.type());
assertEquals(DataMode.OPTIONAL, col.mode());
assertTrue(col.isNullable());
assertTrue(col.isArray());
assertTrue(col.isVariant());
assertEquals(StructureType.VARIANT, col.structureType());
VariantMetadata union = col.variantSchema();
assertNotNull(union);
assertEquals(2, union.size());
assertTrue(union.hasType(MinorType.BIGINT));
assertTrue(union.hasType(MinorType.VARCHAR));
assertFalse(union.hasType(MinorType.INT));
Collection<MinorType> types = union.types();
assertNotNull(types);
assertEquals(2, types.size());
assertTrue(types.contains(MinorType.BIGINT));
assertTrue(types.contains(MinorType.VARCHAR));
BatchSchema batchSchema = ((TupleSchema) schema).toBatchSchema(SelectionVectorMode.NONE);
MaterializedField field = batchSchema.getColumn(0);
assertEquals("list", field.getName());
MajorType majorType = field.getType();
assertEquals(MinorType.LIST, majorType.getMinorType());
assertEquals(DataMode.OPTIONAL, majorType.getMode());
assertEquals(2, majorType.getSubTypeCount());
List<MinorType> subtypes = majorType.getSubTypeList();
assertEquals(2, subtypes.size());
assertTrue(subtypes.contains(MinorType.BIGINT));
assertTrue(subtypes.contains(MinorType.VARCHAR));
}
use of org.apache.drill.common.types.TypeProtos.MinorType in project drill by axbaretto.
the class TestTupleSchema method testUnionSchema.
@Test
public void testUnionSchema() {
TupleMetadata schema = new SchemaBuilder().addUnion("u").addType(MinorType.BIGINT).addType(MinorType.VARCHAR).resumeSchema().buildSchema();
assertEquals(1, schema.size());
ColumnMetadata col = schema.metadata(0);
assertTrue(col instanceof VariantColumnMetadata);
assertEquals(MinorType.UNION, col.type());
assertEquals(DataMode.OPTIONAL, col.mode());
assertTrue(col.isNullable());
assertFalse(col.isArray());
assertTrue(col.isVariant());
assertEquals(StructureType.VARIANT, col.structureType());
VariantMetadata union = col.variantSchema();
assertNotNull(union);
assertEquals(2, union.size());
assertTrue(union.hasType(MinorType.BIGINT));
assertTrue(union.hasType(MinorType.VARCHAR));
assertFalse(union.hasType(MinorType.INT));
Collection<MinorType> types = union.types();
assertNotNull(types);
assertEquals(2, types.size());
assertTrue(types.contains(MinorType.BIGINT));
assertTrue(types.contains(MinorType.VARCHAR));
BatchSchema batchSchema = ((TupleSchema) schema).toBatchSchema(SelectionVectorMode.NONE);
MaterializedField field = batchSchema.getColumn(0);
assertEquals("u", field.getName());
MajorType majorType = field.getType();
assertEquals(MinorType.UNION, majorType.getMinorType());
assertEquals(DataMode.OPTIONAL, majorType.getMode());
assertEquals(2, majorType.getSubTypeCount());
List<MinorType> subtypes = majorType.getSubTypeList();
assertEquals(2, subtypes.size());
assertTrue(subtypes.contains(MinorType.BIGINT));
assertTrue(subtypes.contains(MinorType.VARCHAR));
}
use of org.apache.drill.common.types.TypeProtos.MinorType in project drill by axbaretto.
the class TestDrillbitResilience method assertDrillbitsOk.
/**
* Check that all the drillbits are ok.
* <p/>
* <p>The current implementation does this by counting the number of drillbits using a query.
*/
private static void assertDrillbitsOk() {
final SingleRowListener listener = new SingleRowListener() {
private final BufferAllocator bufferAllocator = RootAllocatorFactory.newRoot(zkHelper.getConfig());
private final RecordBatchLoader loader = new RecordBatchLoader(bufferAllocator);
@Override
public void rowArrived(final QueryDataBatch queryResultBatch) {
// load the single record
final QueryData queryData = queryResultBatch.getHeader();
try {
loader.load(queryData.getDef(), queryResultBatch.getData());
// TODO: Clean: DRILL-2933: That load(...) no longer throws
// SchemaChangeException, so check/clean catch clause below.
} catch (final SchemaChangeException e) {
fail(e.toString());
}
assertEquals(1, loader.getRecordCount());
// there should only be one column
final BatchSchema batchSchema = loader.getSchema();
assertEquals(1, batchSchema.getFieldCount());
// the column should be an integer
final MaterializedField countField = batchSchema.getColumn(0);
final MinorType fieldType = countField.getType().getMinorType();
assertEquals(MinorType.BIGINT, fieldType);
// get the column value
final VectorWrapper<?> vw = loader.iterator().next();
final Object obj = vw.getValueVector().getAccessor().getObject(0);
assertTrue(obj instanceof Long);
final Long countValue = (Long) obj;
// assume this means all the drillbits are still ok
assertEquals(drillbits.size(), countValue.intValue());
loader.clear();
}
@Override
public void cleanup() {
DrillAutoCloseables.closeNoChecked(bufferAllocator);
}
};
try {
QueryTestUtil.testWithListener(drillClient, QueryType.SQL, "select count(*) from sys.memory", listener);
listener.waitForCompletion();
final QueryState state = listener.getQueryState();
assertTrue(String.format("QueryState should be COMPLETED (and not %s).", state), state == QueryState.COMPLETED);
} catch (final Exception e) {
throw new RuntimeException("Couldn't query active drillbits", e);
}
final List<DrillPBError> errorList = listener.getErrorList();
assertTrue("There should not be any errors when checking if Drillbits are OK.", errorList.isEmpty());
}
use of org.apache.drill.common.types.TypeProtos.MinorType in project drill by axbaretto.
the class ColumnReaderFactory method buildColumnReader.
public static AbstractObjectReader buildColumnReader(ValueVector vector) {
MajorType major = vector.getField().getType();
MinorType type = major.getMinorType();
DataMode mode = major.getMode();
switch(type) {
case GENERIC_OBJECT:
case LATE:
case NULL:
case LIST:
case MAP:
throw new UnsupportedOperationException(type.toString());
default:
switch(mode) {
case OPTIONAL:
return BaseScalarReader.build(vector, newAccessor(type, nullableReaders));
case REQUIRED:
return BaseScalarReader.build(vector, newAccessor(type, requiredReaders));
case REPEATED:
return ScalarArrayReader.build((RepeatedValueVector) vector, newAccessor(type, elementReaders));
default:
throw new UnsupportedOperationException(mode.toString());
}
}
}
Aggregations