Refine search
public static boolean isArrayType(Type type) { return type.getTypeSignature().getBase().equals(StandardTypes.ARRAY); }
public static MapType mapType(Type keyType, Type valueType) { return (MapType) TYPE_MANAGER.getParameterizedType(StandardTypes.MAP, ImmutableList.of( TypeSignatureParameter.of(keyType.getTypeSignature()), TypeSignatureParameter.of(valueType.getTypeSignature()))); } }
private boolean isSupportedType(Type type) { if (isSupportedPrimitive(type)) { return true; } if (type.getTypeSignature().getBase().equalsIgnoreCase(ARRAY)) { checkArgument(type.getTypeParameters().size() == 1, "expecting exactly one type parameter for array"); return isSupportedPrimitive(type.getTypeParameters().get(0)); } if (type.getTypeSignature().getBase().equalsIgnoreCase(MAP)) { List<Type> typeParameters = type.getTypeParameters(); checkArgument(typeParameters.size() == 2, "expecting exactly two type parameters for map"); checkArgument(typeParameters.get(0) instanceof VarcharType, "Unsupported column type '%s' for map key", typeParameters.get(0)); return isSupportedPrimitive(type.getTypeParameters().get(1)); } return false; }
private static Block serializeStruct(Type type, BlockBuilder builder, Object object) { if (object == null) { requireNonNull(builder, "builder is null"); builder.appendNull(); return builder.build(); } if (builder == null) { builder = type.createBlockBuilder(null, 1); } BlockBuilder currentBuilder = builder.beginBlockEntry(); List<Type> typeParameters = type.getTypeParameters(); for (int i = 0; i < typeParameters.size(); i++) { Optional<String> fieldName = type.getTypeSignature().getParameters().get(i).getNamedTypeSignature().getName(); String name = ""; if (fieldName.isPresent()) { name = fieldName.get().toLowerCase(ENGLISH); } Object value = ((Map) object).get(name); serializeObject(typeParameters.get(i), currentBuilder, value); } builder.closeEntry(); return (Block) type.getObject(builder, 0); }
break; return primitiveType.getTypeSignature(); case MAP: MapTypeInfo mapTypeInfo = (MapTypeInfo) typeInfo; return new TypeSignature( StandardTypes.MAP, ImmutableList.of(TypeSignatureParameter.of(keyType), TypeSignatureParameter.of(valueType))); case LIST: ListTypeInfo listTypeInfo = (ListTypeInfo) typeInfo; return new TypeSignature( StandardTypes.ARRAY, ImmutableList.of(TypeSignatureParameter.of(elementType))); case STRUCT: StructTypeInfo structTypeInfo = (StructTypeInfo) typeInfo; TypeSignature typeSignature = getTypeSignature(structFieldTypeInfos.get(i)); String rowFieldName = structFieldNames.get(i).toLowerCase(Locale.US); typeSignatureBuilder.add(TypeSignatureParameter.of(new NamedTypeSignature(Optional.of(new RowFieldName(rowFieldName, false)), typeSignature)));
int repetitionLevel = columnIO.getRepetitionLevel(); int definitionLevel = columnIO.getDefinitionLevel(); if (ROW.equals(type.getTypeSignature().getBase())) { GroupColumnIO groupColumnIO = (GroupColumnIO) columnIO; List<Type> parameters = type.getTypeParameters(); ImmutableList.Builder<Optional<Field>> fieldsBuilder = ImmutableList.builder(); List<TypeSignatureParameter> fields = type.getTypeSignature().getParameters(); boolean structHasParameters = false; for (int i = 0; i < fields.size(); i++) { NamedTypeSignature namedTypeSignature = fields.get(i).getNamedTypeSignature(); String name = namedTypeSignature.getName().get().toLowerCase(Locale.ENGLISH); Optional<Field> field = constructField(parameters.get(i), lookupColumnByName(groupColumnIO, name)); structHasParameters |= field.isPresent(); fieldsBuilder.add(field); else if (MAP.equals(type.getTypeSignature().getBase())) { GroupColumnIO groupColumnIO = (GroupColumnIO) columnIO; MapType mapType = (MapType) type; return Optional.of(new GroupField(type, repetitionLevel, definitionLevel, required, ImmutableList.of(keyField, valueField))); else if (ARRAY.equals(type.getTypeSignature().getBase())) { GroupColumnIO groupColumnIO = (GroupColumnIO) columnIO; List<Type> types = type.getTypeParameters(); return Optional.empty();
private static Class<?> getObjectType(Type type) { if (type.equals(BOOLEAN)) { return boolean.class; } if (type.equals(BIGINT)) { return long.class; } if (type.equals(DOUBLE)) { return double.class; } if (type.equals(VARCHAR)) { return String.class; } if (type.getTypeSignature().getBase().equals(ARRAY)) { getObjectType(type.getTypeParameters().get(0)); return List.class; } if (type.getTypeSignature().getBase().equals(MAP)) { getObjectType(type.getTypeParameters().get(0)); getObjectType(type.getTypeParameters().get(1)); return Map.class; } throw new IllegalArgumentException("Unsupported argument type: " + type.getDisplayName()); } }
return ObjectInspectorFactory.getStandardListObjectInspector(getJavaObjectInspector(type.getTypeParameters().get(0))); ObjectInspector keyObjectInspector = getJavaObjectInspector(type.getTypeParameters().get(0)); ObjectInspector valueObjectInspector = getJavaObjectInspector(type.getTypeParameters().get(1)); return ObjectInspectorFactory.getStandardMapObjectInspector(keyObjectInspector, valueObjectInspector); type.getTypeSignature().getParameters().stream() .map(parameter -> parameter.getNamedTypeSignature().getName().get()) .collect(toList()),
@Setup public void setup() { MetadataManager metadata = MetadataManager.createTestMetadataManager(); ExpressionCompiler compiler = new ExpressionCompiler(metadata, new PageFunctionCompiler(metadata, 0)); ImmutableList.Builder<RowExpression> projectionsBuilder = ImmutableList.builder(); Block[] blocks = new Block[TYPES.size()]; Type returnType = new ArrayType(BOOLEAN); for (int i = 0; i < TYPES.size(); i++) { Type elementType = TYPES.get(i); ArrayType arrayType = new ArrayType(elementType); Signature signature = new Signature("transform", FunctionKind.SCALAR, returnType.getTypeSignature(), arrayType.getTypeSignature(), parseTypeSignature("function(bigint,boolean)")); Signature greaterThan = new Signature("$operator$" + GREATER_THAN.name(), FunctionKind.SCALAR, BOOLEAN.getTypeSignature(), BIGINT.getTypeSignature(), BIGINT.getTypeSignature()); projectionsBuilder.add(new CallExpression(signature, returnType, ImmutableList.of( new InputReferenceExpression(0, arrayType), new LambdaDefinitionExpression( ImmutableList.of(BIGINT), ImmutableList.of("x"), new CallExpression(greaterThan, BOOLEAN, ImmutableList.of(new VariableReferenceExpression("x", BIGINT), new ConstantExpression(0L, BIGINT))))))); blocks[i] = createChannel(POSITIONS, ARRAY_SIZE, arrayType); } ImmutableList<RowExpression> projections = projectionsBuilder.build(); pageProcessor = compiler.compilePageProcessor(Optional.empty(), projections).get(); pageBuilder = new PageBuilder(projections.stream().map(RowExpression::getType).collect(Collectors.toList())); page = new Page(blocks); }
private static List<OrcType> toOrcType(int nextFieldTypeIndex, Type type) return ImmutableList.of(new OrcType(OrcTypeKind.BOOLEAN)); return ImmutableList.of(new OrcType(OrcTypeKind.BYTE)); return ImmutableList.of(new OrcType(OrcTypeKind.SHORT)); return ImmutableList.of(new OrcType(OrcTypeKind.DECIMAL, decimalType.getPrecision(), decimalType.getScale())); if (type.getTypeSignature().getBase().equals(ARRAY)) { return createOrcArrayType(nextFieldTypeIndex, type.getTypeParameters().get(0)); if (type.getTypeSignature().getBase().equals(MAP)) { return createOrcMapType(nextFieldTypeIndex, type.getTypeParameters().get(0), type.getTypeParameters().get(1)); if (type.getTypeSignature().getBase().equals(ROW)) { List<String> fieldNames = new ArrayList<>(); for (int i = 0; i < type.getTypeSignature().getParameters().size(); i++) { TypeSignatureParameter parameter = type.getTypeSignature().getParameters().get(i); fieldNames.add(parameter.getNamedTypeSignature().getName().orElse("field" + i));
public static Signature dereferenceSignature(Type returnType, RowType rowType) { return internalScalarFunction(DEREFERENCE, returnType.getTypeSignature(), ImmutableList.of(rowType.getTypeSignature(), BigintType.BIGINT.getTypeSignature())); } }
public static boolean isRowType(Type type) { return type.getTypeSignature().getBase().equals(StandardTypes.ROW); }
private TypeCompatibility typeCompatibilityForCovariantParametrizedType(Type fromType, Type toType) { checkState(fromType.getClass().equals(toType.getClass())); ImmutableList.Builder<TypeSignatureParameter> commonParameterTypes = ImmutableList.builder(); List<Type> fromTypeParameters = fromType.getTypeParameters(); List<Type> toTypeParameters = toType.getTypeParameters(); if (fromTypeParameters.size() != toTypeParameters.size()) { return TypeCompatibility.incompatible(); } boolean coercible = true; for (int i = 0; i < fromTypeParameters.size(); i++) { TypeCompatibility compatibility = compatibility(fromTypeParameters.get(i), toTypeParameters.get(i)); if (!compatibility.isCompatible()) { return TypeCompatibility.incompatible(); } coercible &= compatibility.isCoercible(); commonParameterTypes.add(TypeSignatureParameter.of(compatibility.getCommonSuperType().getTypeSignature())); } String typeBase = fromType.getTypeSignature().getBase(); return TypeCompatibility.compatible(getType(new TypeSignature(typeBase, commonParameterTypes.build())), coercible); }
@Test public void testRowTypeLookup() { functionAssertions.getMetadata().getType(parseTypeSignature("row(a bigint)")); Type type = functionAssertions.getMetadata().getType(parseTypeSignature("row(b bigint)")); assertEquals(type.getTypeSignature().getParameters().size(), 1); assertEquals(type.getTypeSignature().getParameters().get(0).getNamedTypeSignature().getName().get(), "b"); }
Signature signature = internalOperator( CAST.name(), toTypes.get(i).getTypeSignature(), ImmutableList.of(fromTypes.get(i).getTypeSignature())); ScalarFunctionImplementation function = functionRegistry.getScalarFunctionImplementation(signature); Type currentFromType = fromTypes.get(i); if (currentFromType.equals(UNKNOWN)) { body.append(singleRowBlockWriter.invoke("appendNull", BlockBuilder.class).pop());
@Override public InternalAggregationFunction specialize(BoundVariables boundVariables, int arity, TypeManager typeManager, FunctionRegistry functionRegistry) { Type keyType = boundVariables.getTypeVariable("K"); Type valueType = boundVariables.getTypeVariable("V"); MapType outputType = (MapType) typeManager.getParameterizedType(StandardTypes.MAP, ImmutableList.of( TypeSignatureParameter.of(keyType.getTypeSignature()), TypeSignatureParameter.of(valueType.getTypeSignature()))); return generateAggregation(keyType, valueType, outputType); }
public static boolean isMapType(Type type) { return type.getTypeSignature().getBase().equals(StandardTypes.MAP); }
Type type = types.get(i); if (BOOLEAN.equals(type)) { checkArgument(value instanceof Boolean, "Expected value %d to be an instance of Boolean, but is a %s", i, value.getClass().getSimpleName()); "Expected value %d to be an instance of Slice, but is a %s", i, value.getClass().getSimpleName()); else if (type.getTypeSignature().getBase().equals("array")) { checkArgument(value instanceof Block, "Expected value %d to be an instance of Block, but is a %s", i, value.getClass().getSimpleName()); throw new IllegalStateException("Unsupported column type " + types.get(i));
private ColumnChunk readStruct(GroupField field) throws IOException { List<TypeSignatureParameter> fields = field.getType().getTypeSignature().getParameters(); Block[] blocks = new Block[fields.size()]; ColumnChunk columnChunk = null; List<Optional<Field>> parameters = field.getChildren(); for (int i = 0; i < fields.size(); i++) { Optional<Field> parameter = parameters.get(i); if (parameter.isPresent()) { columnChunk = readColumnChunk(parameter.get()); blocks[i] = columnChunk.getBlock(); } } for (int i = 0; i < fields.size(); i++) { if (blocks[i] == null) { blocks[i] = RunLengthEncodedBlock.create(field.getType(), null, columnChunk.getBlock().getPositionCount()); } } BooleanList structIsNull = StructColumnReader.calculateStructOffsets(field, columnChunk.getDefinitionLevels(), columnChunk.getRepetitionLevels()); boolean[] structIsNullVector = structIsNull.toBooleanArray(); Block rowBlock = RowBlock.fromFieldBlocks(structIsNullVector.length, Optional.of(structIsNullVector), blocks); return new ColumnChunk(rowBlock, columnChunk.getDefinitionLevels(), columnChunk.getRepetitionLevels()); }
switch (mapSize) { case 1: keys = ImmutableList.of("do_not_use"); break; case 13: keys = ImmutableList.of("is_inverted", "device_model", "country", "carrier_id", "network_type", "os_version", "device_brand", "device_type", "interface", "device_os", "app_version", "device_type_class", "browser"); break; "$operator$" + SUBSCRIPT.name(), FunctionKind.SCALAR, mapType.getValueType().getTypeSignature(), mapType.getTypeSignature(), mapType.getKeyType().getTypeSignature()); for (int i = 0; i < mapSize; i++) { projectionsBuilder.add(new CallExpression( signature, mapType.getValueType(), ImmutableList.of(field(0, mapType), constant(utf8Slice(keys.get(i)), createUnboundedVarcharType()))));