use of org.apache.drill.common.types.TypeProtos.MinorType in project drill by axbaretto.
the class PcapRecordReader method initCols.
private ImmutableList<ProjectedColumnInfo> initCols(final Schema schema) {
ImmutableList.Builder<ProjectedColumnInfo> pciBuilder = ImmutableList.builder();
ColumnDto column;
for (int i = 0; i < schema.getNumberOfColumns(); i++) {
column = schema.getColumnByIndex(i);
final String name = column.getColumnName().toLowerCase();
final PcapTypes type = column.getColumnType();
TypeProtos.MinorType minorType = TYPES.get(type);
ProjectedColumnInfo pci = getProjectedColumnInfo(column, name, minorType);
pciBuilder.add(pci);
}
return pciBuilder.build();
}
use of org.apache.drill.common.types.TypeProtos.MinorType in project drill by axbaretto.
the class ParquetToDrillTypeConverter method toMajorType.
public static TypeProtos.MajorType toMajorType(PrimitiveType.PrimitiveTypeName primitiveTypeName, int length, TypeProtos.DataMode mode, ConvertedType convertedType, int precision, int scale, OptionManager options) {
MinorType minorType = getMinorType(primitiveTypeName, length, convertedType, precision, options);
TypeProtos.MajorType.Builder typeBuilder = TypeProtos.MajorType.newBuilder().setMinorType(minorType).setMode(mode);
if (CoreDecimalUtility.isDecimalType(minorType)) {
typeBuilder.setPrecision(precision).setScale(scale);
}
return typeBuilder.build();
}
use of org.apache.drill.common.types.TypeProtos.MinorType in project drill by axbaretto.
the class ColumnDef method makeDefaultGenerator.
private void makeDefaultGenerator() {
MinorType minorType = mockCol.getMinorType();
switch(minorType) {
case BIGINT:
break;
case BIT:
generator = new BooleanGen();
break;
case DATE:
break;
case DECIMAL18:
break;
case DECIMAL28DENSE:
break;
case DECIMAL28SPARSE:
break;
case DECIMAL38DENSE:
break;
case DECIMAL38SPARSE:
break;
case DECIMAL9:
break;
case FIXED16CHAR:
break;
case FIXEDBINARY:
break;
case FIXEDCHAR:
break;
case FLOAT4:
break;
case FLOAT8:
generator = new DoubleGen();
break;
case GENERIC_OBJECT:
break;
case INT:
generator = new IntGen();
break;
case INTERVAL:
break;
case INTERVALDAY:
break;
case INTERVALYEAR:
break;
case LATE:
break;
case LIST:
break;
case MAP:
break;
case MONEY:
break;
case NULL:
break;
case SMALLINT:
break;
case TIME:
break;
case TIMESTAMP:
break;
case TIMESTAMPTZ:
break;
case TIMETZ:
break;
case TINYINT:
break;
case UINT1:
break;
case UINT2:
break;
case UINT4:
break;
case UINT8:
break;
case UNION:
break;
case VAR16CHAR:
break;
case VARBINARY:
break;
case VARCHAR:
generator = new StringGen();
break;
default:
break;
}
if (generator == null) {
throw new IllegalArgumentException("No default column generator for column " + name + " of type " + minorType);
}
generator.setup(this);
}
use of org.apache.drill.common.types.TypeProtos.MinorType in project drill by axbaretto.
the class MockGroupScanPOP method clone.
@Override
public GroupScan clone(List<SchemaPath> columns) {
if (columns.isEmpty()) {
throw new IllegalArgumentException("No columns for mock scan");
}
List<MockColumn> mockCols = new ArrayList<>();
Pattern p = Pattern.compile("(\\w+)_([isdb])(\\d*)");
for (SchemaPath path : columns) {
String col = path.getLastSegment().getNameSegment().getPath();
if (SchemaPath.DYNAMIC_STAR.equals(col)) {
return this;
}
Matcher m = p.matcher(col);
if (!m.matches()) {
throw new IllegalArgumentException("Badly formatted mock column name: " + col);
}
@SuppressWarnings("unused") String name = m.group(1);
String type = m.group(2);
String length = m.group(3);
int width = 10;
if (!length.isEmpty()) {
width = Integer.parseInt(length);
}
MinorType minorType;
switch(type) {
case "i":
minorType = MinorType.INT;
break;
case "s":
minorType = MinorType.VARCHAR;
break;
case "d":
minorType = MinorType.FLOAT8;
break;
case "b":
minorType = MinorType.BIT;
break;
default:
throw new IllegalArgumentException("Unsupported field type " + type + " for mock column " + col);
}
MockTableDef.MockColumn mockCol = new MockColumn(col, minorType, DataMode.REQUIRED, width, 0, 0, null, 1, null);
mockCols.add(mockCol);
}
MockScanEntry entry = readEntries.get(0);
MockColumn[] types = new MockColumn[mockCols.size()];
mockCols.toArray(types);
MockScanEntry newEntry = new MockScanEntry(entry.records, true, 0, 1, types);
List<MockScanEntry> newEntries = new ArrayList<>();
newEntries.add(newEntry);
return new MockGroupScanPOP(url, newEntries);
}
use of org.apache.drill.common.types.TypeProtos.MinorType in project drill by axbaretto.
the class FieldIdUtil method getFieldId.
public static TypedFieldId getFieldId(ValueVector vector, int id, SchemaPath expectedPath, boolean hyper) {
if (!expectedPath.getRootSegment().getPath().equalsIgnoreCase(vector.getField().getName())) {
return null;
}
PathSegment seg = expectedPath.getRootSegment();
TypedFieldId.Builder builder = TypedFieldId.newBuilder();
if (hyper) {
builder.hyper();
}
if (vector instanceof UnionVector) {
builder.addId(id).remainder(expectedPath.getRootSegment().getChild());
List<MinorType> minorTypes = ((UnionVector) vector).getSubTypes();
MajorType.Builder majorTypeBuilder = MajorType.newBuilder().setMinorType(MinorType.UNION);
for (MinorType type : minorTypes) {
majorTypeBuilder.addSubType(type);
}
MajorType majorType = majorTypeBuilder.build();
builder.intermediateType(majorType);
if (seg.isLastPath()) {
builder.finalType(majorType);
return builder.build();
} else {
return getFieldIdIfMatchesUnion((UnionVector) vector, builder, false, seg.getChild());
}
} else if (vector instanceof ListVector) {
ListVector list = (ListVector) vector;
builder.intermediateType(vector.getField().getType());
builder.addId(id);
return getFieldIdIfMatches(list, builder, true, expectedPath.getRootSegment().getChild());
} else if (vector instanceof AbstractContainerVector) {
// we're looking for a multi path.
AbstractContainerVector c = (AbstractContainerVector) vector;
builder.intermediateType(vector.getField().getType());
builder.addId(id);
return getFieldIdIfMatches(c, builder, true, expectedPath.getRootSegment().getChild());
} else {
builder.intermediateType(vector.getField().getType());
builder.addId(id);
builder.finalType(vector.getField().getType());
if (seg.isLastPath()) {
return builder.build();
} else {
PathSegment child = seg.getChild();
if (child.isArray() && child.isLastPath()) {
builder.remainder(child);
builder.withIndex();
builder.finalType(vector.getField().getType().toBuilder().setMode(DataMode.OPTIONAL).build());
return builder.build();
} else {
return null;
}
}
}
}
Aggregations