private static Optional<Symbol> newGeometrySymbol(Context context, Expression expression, Metadata metadata) { if (expression instanceof SymbolReference) { return Optional.empty(); } return Optional.of(context.getSymbolAllocator().newSymbol(expression, metadata.getType(GEOMETRY_TYPE_SIGNATURE))); }
private static Optional<Symbol> newGeometrySymbol(Context context, Expression expression, Metadata metadata) { if (expression instanceof SymbolReference) { return Optional.empty(); } return Optional.of(context.getSymbolAllocator().newSymbol(expression, metadata.getType(GEOMETRY_TYPE_SIGNATURE))); }
private boolean isIntegralType(TypeSignature targetType) { switch (targetType.getBase()) { case StandardTypes.BIGINT: case StandardTypes.INTEGER: case StandardTypes.SMALLINT: case StandardTypes.TINYINT: return true; case StandardTypes.DECIMAL: DecimalType decimalType = (DecimalType) metadata.getType(targetType); return decimalType.getScale() == 0; default: return false; } }
protected Function<Column, Type> columnTypeGetter() { return column -> { String typeName = column.getType(); Type type = prestoServer.getMetadata().getType(parseTypeSignature(typeName)); if (type == null) { throw new AssertionError("Unhandled type: " + typeName); } return type; }; } }
private boolean isIntegralType(TypeSignature targetType) { switch (targetType.getBase()) { case StandardTypes.BIGINT: case StandardTypes.INTEGER: case StandardTypes.SMALLINT: case StandardTypes.TINYINT: return true; case StandardTypes.DECIMAL: DecimalType decimalType = (DecimalType) metadata.getType(targetType); return decimalType.getScale() == 0; default: return false; } }
@Override protected Type _deserialize(String value, DeserializationContext context) { Type type = metadata.getType(parseTypeSignature(value)); if (type == null) { throw new IllegalArgumentException(String.valueOf("Unknown type " + value)); } return type; } }
private ColumnStatisticsAggregation createAggregation(QualifiedName functionName, SymbolReference input, Type inputType, Type outputType) { Signature signature = metadata.getFunctionRegistry().resolveFunction(functionName, TypeSignatureProvider.fromTypes(ImmutableList.of(inputType))); Type resolvedType = metadata.getType(getOnlyElement(signature.getArgumentTypes())); verify(resolvedType.equals(inputType), "resolved function input type does not match the input type: %s != %s", resolvedType, inputType); return new ColumnStatisticsAggregation( new AggregationNode.Aggregation( new FunctionCall(functionName, ImmutableList.of(input)), signature, Optional.empty()), outputType); }
private ColumnStatisticsAggregation createAggregation(QualifiedName functionName, SymbolReference input, Type inputType, Type outputType) { Signature signature = metadata.getFunctionRegistry().resolveFunction(functionName, TypeSignatureProvider.fromTypes(ImmutableList.of(inputType))); Type resolvedType = metadata.getType(getOnlyElement(signature.getArgumentTypes())); verify(resolvedType.equals(inputType), "resolved function input type does not match the input type: %s != %s", resolvedType, inputType); return new ColumnStatisticsAggregation( new AggregationNode.Aggregation( new FunctionCall(functionName, ImmutableList.of(input)), signature, Optional.empty()), outputType); }
@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"); }
@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"); }
Type type = metadata.getType(argument.getType()); checkCondition(type != null, INVALID_PROCEDURE_DEFINITION, "Unknown procedure argument type: %s", argument.getType());
if (name.toString().equals(NAME) && call.getArguments().size() == 1) { Expression geometry = getOnlyElement(call.getArguments()); Symbol envelopeSymbol = context.getSymbolAllocator().newSymbol("envelope", metadata.getType(GEOMETRY_TYPE_SIGNATURE)); if (geometry instanceof FunctionCall && ((FunctionCall) geometry).getName().toString().equalsIgnoreCase("ST_Envelope")) { envelopeAssignments.put(envelopeSymbol, geometry);
@VisibleForTesting public static final class ExtractSpatialLeftJoin implements Rule<JoinNode> { private static final Pattern<JoinNode> PATTERN = join().matching(node -> node.getCriteria().isEmpty() && node.getFilter().isPresent() && node.getType() == LEFT); private final Metadata metadata; private final SplitManager splitManager; private final PageSourceManager pageSourceManager; private final SqlParser sqlParser; public ExtractSpatialLeftJoin(Metadata metadata, SplitManager splitManager, PageSourceManager pageSourceManager, SqlParser sqlParser) { this.metadata = requireNonNull(metadata, "metadata is null"); this.splitManager = requireNonNull(splitManager, "splitManager is null"); this.pageSourceManager = requireNonNull(pageSourceManager, "pageSourceManager is null"); this.sqlParser = requireNonNull(sqlParser, "sqlParser is null"); } @Override public boolean isEnabled(Session session) { return isSpatialJoinEnabled(session); } @Override public Pattern<JoinNode> getPattern() { return PATTERN; }
if (name.toString().equals(NAME) && call.getArguments().size() == 1) { Expression geometry = getOnlyElement(call.getArguments()); Symbol envelopeSymbol = context.getSymbolAllocator().newSymbol("envelope", metadata.getType(GEOMETRY_TYPE_SIGNATURE)); if (geometry instanceof FunctionCall && ((FunctionCall) geometry).getName().toString().equalsIgnoreCase("ST_Envelope")) { envelopeAssignments.put(envelopeSymbol, geometry);
@Override protected Object visitGenericLiteral(GenericLiteral node, ConnectorSession session) { Type type = metadata.getType(parseTypeSignature(node.getType())); if (type == null) { throw new SemanticException(TYPE_MISMATCH, node, "Unknown type: " + node.getType()); } if (JSON.equals(type)) { Signature operatorSignature = new Signature("json_parse", SCALAR, JSON.getTypeSignature(), VARCHAR.getTypeSignature()); return functionInvoker.invoke(operatorSignature, session, ImmutableList.of(utf8Slice(node.getValue()))); } try { Signature signature = metadata.getFunctionRegistry().getCoercion(VARCHAR, type); return functionInvoker.invoke(signature, session, ImmutableList.of(utf8Slice(node.getValue()))); } catch (IllegalArgumentException e) { throw new SemanticException(TYPE_MISMATCH, node, "No literal form for type %s", type); } }
@Override protected Object visitGenericLiteral(GenericLiteral node, ConnectorSession session) { Type type = metadata.getType(parseTypeSignature(node.getType())); if (type == null) { throw new SemanticException(TYPE_MISMATCH, node, "Unknown type: " + node.getType()); } if (JSON.equals(type)) { Signature operatorSignature = new Signature("json_parse", SCALAR, JSON.getTypeSignature(), VARCHAR.getTypeSignature()); return functionInvoker.invoke(operatorSignature, session, ImmutableList.of(utf8Slice(node.getValue()))); } try { Signature signature = metadata.getFunctionRegistry().getCoercion(VARCHAR, type); return functionInvoker.invoke(signature, session, ImmutableList.of(utf8Slice(node.getValue()))); } catch (IllegalArgumentException e) { throw new SemanticException(TYPE_MISMATCH, node, "No literal form for type %s", type); } }
Type type; try { type = metadata.getType(parseTypeSignature(element.getType()));
Type type; try { type = metadata.getType(parseTypeSignature(element.getType()));
Type targetType = metadata.getType(parseTypeSignature(node.getType())); if (targetType == null) { throw new IllegalArgumentException("Unsupported type: " + node.getType());
Type targetType = metadata.getType(parseTypeSignature(node.getType())); if (targetType == null) { throw new IllegalArgumentException("Unsupported type: " + node.getType());