@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } return this.getTypeSignature().equals(((Type) o).getTypeSignature()); }
private void verifyTypeSignature(Symbol symbol, TypeSignature expected, TypeSignature actual) { // UNKNOWN should be considered as a wildcard type, which matches all the other types TypeManager typeManager = metadata.getTypeManager(); if (!actual.equals(UNKNOWN.getTypeSignature()) && !typeManager.isTypeOnlyCoercion(typeManager.getType(actual), typeManager.getType(expected))) { checkArgument(expected.equals(actual), "type of symbol '%s' is expected to be %s, but the actual type is %s", symbol, expected, actual); } } }
@VisibleForTesting public static ParametricAggregation parseFunctionDefinitionWithTypesConstraint(Class<?> clazz, TypeSignature returnType, List<TypeSignature> argumentTypes) { requireNonNull(returnType, "returnType is null"); requireNonNull(argumentTypes, "argumentTypes is null"); for (ParametricAggregation aggregation : parseFunctionDefinitions(clazz)) { if (aggregation.getSignature().getReturnType().equals(returnType) && aggregation.getSignature().getArgumentTypes().equals(argumentTypes)) { return aggregation; } } throw new IllegalArgumentException(String.format("No method with return type %s and arguments %s", returnType, argumentTypes)); }
private static void checkNoLiteralVariableUsageAcrossTypes(TypeSignature typeSignature, Map<String, TypeSignature> existingUsages) { List<TypeSignatureParameter> variables = typeSignature.getParameters().stream() .filter(TypeSignatureParameter::isVariable) .collect(toList()); for (TypeSignatureParameter variable : variables) { TypeSignature existing = existingUsages.get(variable.getVariable()); if (existing != null && !existing.equals(typeSignature)) { throw new UnsupportedOperationException("Literal parameters may not be shared across different types"); } existingUsages.put(variable.getVariable(), typeSignature); } for (TypeSignatureParameter parameter : typeSignature.getParameters()) { if (parameter.isLongLiteral() || parameter.isVariable()) { continue; } checkNoLiteralVariableUsageAcrossTypes(parameter.getTypeSignatureOrNamedTypeSignature().get(), existingUsages); } }
private boolean satisfiesCoercion(boolean allowCoercion, Type fromType, TypeSignature toTypeSignature) { if (allowCoercion) { return typeManager.canCoerce(fromType, typeManager.getType(toTypeSignature)); } else { return fromType.getTypeSignature().equals(toTypeSignature); } }
private List<Document> guessTableFields(SchemaTableName schemaTableName) { String schemaName = schemaTableName.getSchemaName(); String tableName = schemaTableName.getTableName(); MongoDatabase db = client.getDatabase(schemaName); Document doc = db.getCollection(tableName).find().first(); if (doc == null) { // no records at the collection return ImmutableList.of(); } ImmutableList.Builder<Document> builder = ImmutableList.builder(); for (String key : doc.keySet()) { Object value = doc.get(key); Optional<TypeSignature> fieldType = guessFieldType(value); if (fieldType.isPresent()) { Document metadata = new Document(); metadata.append(FIELDS_NAME_KEY, key); metadata.append(FIELDS_TYPE_KEY, fieldType.get().toString()); metadata.append(FIELDS_HIDDEN_KEY, key.equals("_id") && fieldType.get().equals(OBJECT_ID.getTypeSignature())); builder.add(metadata); } else { log.debug("Unable to guess field type from %s : %s", value == null ? "null" : value.getClass().getName(), value); } } return builder.build(); }
checkArgument(argumentTypes.get(1).getBase().equals(StandardTypes.BIGINT), "Second argument must be a BIGINT"); TypeSignature elementType = argumentTypes.get(0).getTypeParametersAsTypeSignatures().get(0); checkArgument(returnType.equals(elementType), "[] return type does not match ARRAY element type"); checkArgument(returnType.equals(valueType), "[] return type does not match MAP value type");
private static BytecodeNode cast( BytecodeGeneratorContext generatorContext, BytecodeNode argument, Type actualType, TypeSignature requiredType) { if (actualType.getTypeSignature().equals(requiredType)) { return argument; } Signature function = generatorContext .getRegistry() .getCoercion(actualType.getTypeSignature(), requiredType); // TODO: do we need a full function call? (nullability checks, etc) return generatorContext.generateCall(function.getName(), generatorContext.getRegistry().getScalarFunctionImplementation(function), ImmutableList.of(argument)); } }
public static boolean canCoerce(TypeSignature actualType, TypeSignature expectedType) { Optional<TypeSignature> commonSuperTypeSignature = getCommonSuperTypeSignature(actualType, expectedType); return commonSuperTypeSignature.isPresent() && commonSuperTypeSignature.get().equals(expectedType); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } return this.getTypeSignature().equals(((Type) o).getTypeSignature()); }
@Override void validateSignature(TypeSignature returnType, List<TypeSignature> argumentTypes) { validateOperatorSignature(this, returnType, argumentTypes, 2); checkArgument(argumentTypes.get(0).getBase().equals(StandardTypes.ARRAY) || argumentTypes.get(0).getBase().equals(StandardTypes.MAP), "First argument must be an ARRAY or MAP"); if (argumentTypes.get(0).getBase().equals(StandardTypes.ARRAY)) { checkArgument(argumentTypes.get(1).getBase().equals(StandardTypes.BIGINT), "Second argument must be a BIGINT"); TypeSignature elementType = argumentTypes.get(0).getTypeParametersAsTypeSignatures().get(0); checkArgument(returnType.equals(elementType), "[] return type does not match ARRAY element type"); } else { TypeSignature valueType = argumentTypes.get(0).getTypeParametersAsTypeSignatures().get(1); checkArgument(returnType.equals(valueType), "[] return type does not match MAP value type"); } } },
if (actualType.equals(expectedType)) { return true;
private BytecodeNode cast( BytecodeGeneratorContext generatorContext, BytecodeNode argument, Type actualType, TypeSignature requiredType) { if (actualType.getTypeSignature().equals(requiredType)) { return argument; } Signature function = generatorContext .getRegistry() .getCoercion(actualType.getTypeSignature(), requiredType); // TODO: do we need a full function call? (nullability checks, etc) return generatorContext.generateCall(function.getName(), generatorContext.getRegistry().getScalarFunctionImplementation(function), ImmutableList.of(argument)); } }