@Override public String getDisplayName() { if (length == UNBOUNDED_LENGTH) { return getTypeSignature().getBase(); } return getTypeSignature().toString(); }
private static PropertyMetadata<?> stringListSessionProperty(TypeManager typeManager, String name, String description) { return new PropertyMetadata<>( name, description, typeManager.getParameterizedType(ARRAY, ImmutableList.of(TypeSignatureParameter.of(createUnboundedVarcharType().getTypeSignature()))), List.class, ImmutableList.of(), false, value -> ImmutableList.copyOf(stringList(value).stream() .map(s -> s.toLowerCase(ENGLISH)) .collect(toList())), value -> value); }
@Test public void testVarchar() { assertEquals(VARCHAR.getTypeSignature().toString(), "varchar"); assertEquals(createVarcharType(42).getTypeSignature().toString(), "varchar(42)"); assertEquals(parseTypeSignature("varchar"), createUnboundedVarcharType().getTypeSignature()); assertEquals(createUnboundedVarcharType().getTypeSignature(), parseTypeSignature("varchar")); assertEquals(parseTypeSignature("varchar").hashCode(), createUnboundedVarcharType().getTypeSignature().hashCode()); assertNotEquals(createUnboundedVarcharType().getTypeSignature(), parseTypeSignature("varchar(10)")); }
@Test public void testVarchar() { assertEquals(VARCHAR.getTypeSignature().toString(), "varchar"); assertEquals(createVarcharType(42).getTypeSignature().toString(), "varchar(42)"); assertEquals(parseTypeSignature("varchar"), createUnboundedVarcharType().getTypeSignature()); assertEquals(createUnboundedVarcharType().getTypeSignature(), parseTypeSignature("varchar")); assertEquals(parseTypeSignature("varchar").hashCode(), createUnboundedVarcharType().getTypeSignature().hashCode()); assertNotEquals(createUnboundedVarcharType().getTypeSignature(), parseTypeSignature("varchar(10)")); }
typeSignature = createUnboundedVarcharType().getTypeSignature();
return VarcharType.createUnboundedVarcharType().getTypeSignature();
DISTRIBUTED_ON, "Distribution columns", typeManager.getParameterizedType(ARRAY, ImmutableList.of(TypeSignatureParameter.of(createUnboundedVarcharType().getTypeSignature()))), List.class, ImmutableList.of(),
DISTRIBUTED_ON, "Distribution columns", typeManager.getParameterizedType(ARRAY, ImmutableList.of(TypeSignatureParameter.of(createUnboundedVarcharType().getTypeSignature()))), List.class, ImmutableList.of(),
@Inject public TransactionsSystemTable(TypeManager typeManager, TransactionManager transactionManager) { this.transactionsTable = tableMetadataBuilder(TRANSACTIONS_TABLE_NAME) .column("transaction_id", createUnboundedVarcharType()) .column("isolation_level", createUnboundedVarcharType()) .column("read_only", BOOLEAN) .column("auto_commit_context", BOOLEAN) .column("create_time", TIMESTAMP) .column("idle_time_secs", BIGINT) .column("written_catalog", createUnboundedVarcharType()) .column("catalogs", typeManager.getParameterizedType(ARRAY, ImmutableList.of(TypeSignatureParameter.of(createUnboundedVarcharType().getTypeSignature())))) .build(); this.transactionManager = requireNonNull(transactionManager, "transactionManager is null"); }
@Inject public TransactionsSystemTable(TypeManager typeManager, TransactionManager transactionManager) { this.transactionsTable = tableMetadataBuilder(TRANSACTIONS_TABLE_NAME) .column("transaction_id", createUnboundedVarcharType()) .column("isolation_level", createUnboundedVarcharType()) .column("read_only", BOOLEAN) .column("auto_commit_context", BOOLEAN) .column("create_time", TIMESTAMP) .column("idle_time_secs", BIGINT) .column("written_catalog", createUnboundedVarcharType()) .column("catalogs", typeManager.getParameterizedType(ARRAY, ImmutableList.of(TypeSignatureParameter.of(createUnboundedVarcharType().getTypeSignature())))) .build(); this.transactionManager = requireNonNull(transactionManager, "transactionManager is null"); }
@Setup public void setup() { Signature signature = new Signature("array_join", FunctionKind.SCALAR, VARCHAR.getTypeSignature(), new ArrayType(BIGINT).getTypeSignature(), VARCHAR.getTypeSignature()); List<RowExpression> projections = ImmutableList.of( new CallExpression(signature, VARCHAR, ImmutableList.of( field(0, new ArrayType(BIGINT)), constant(Slices.wrappedBuffer(",".getBytes(UTF_8)), VARCHAR)))); MetadataManager metadata = MetadataManager.createTestMetadataManager(); pageProcessor = new ExpressionCompiler(metadata, new PageFunctionCompiler(metadata, 0)) .compilePageProcessor(Optional.empty(), projections) .get(); page = new Page(createChannel(POSITIONS, ARRAY_SIZE)); }
@Setup public void setup() { Signature signature = new Signature("array_join", FunctionKind.SCALAR, VARCHAR.getTypeSignature(), new ArrayType(BIGINT).getTypeSignature(), VARCHAR.getTypeSignature()); List<RowExpression> projections = ImmutableList.of( new CallExpression(signature, VARCHAR, ImmutableList.of( field(0, new ArrayType(BIGINT)), constant(Slices.wrappedBuffer(",".getBytes(UTF_8)), VARCHAR)))); MetadataManager metadata = MetadataManager.createTestMetadataManager(); pageProcessor = new ExpressionCompiler(metadata, new PageFunctionCompiler(metadata, 0)) .compilePageProcessor(Optional.empty(), projections) .get(); page = new Page(createChannel(POSITIONS, ARRAY_SIZE)); }
@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); } }
@Override protected RowExpression visitGenericLiteral(GenericLiteral node, Void context) { Type type; try { type = typeManager.getType(parseTypeSignature(node.getType())); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Unsupported type: " + node.getType()); } if (JSON.equals(type)) { return call( new Signature("json_parse", SCALAR, getType(node).getTypeSignature(), VARCHAR.getTypeSignature()), getType(node), constant(utf8Slice(node.getValue()), VARCHAR)); } return call( castSignature(getType(node), VARCHAR), getType(node), constant(utf8Slice(node.getValue()), VARCHAR)); }
@Override protected RowExpression visitGenericLiteral(GenericLiteral node, Void context) { Type type; try { type = typeManager.getType(parseTypeSignature(node.getType())); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Unsupported type: " + node.getType()); } if (JSON.equals(type)) { return call( new Signature("json_parse", SCALAR, getType(node).getTypeSignature(), VARCHAR.getTypeSignature()), getType(node), constant(utf8Slice(node.getValue()), VARCHAR)); } return call( castSignature(getType(node), VARCHAR), getType(node), constant(utf8Slice(node.getValue()), VARCHAR)); }
@Test public void testCastWithJsonParseOptimization() Signature jsonParseSignature = new Signature("json_parse", SCALAR, JSON.getTypeSignature(), ImmutableList.of(VARCHAR.getTypeSignature()));
ArrayType arrayOfArrayType = new ArrayType(arrayType); Type mapType = typeManager.getParameterizedType(StandardTypes.MAP, ImmutableList.of( TypeSignatureParameter.of(createVarcharType(10).getTypeSignature()), TypeSignatureParameter.of(BOOLEAN.getTypeSignature()))); List<Type> columnTypes = ImmutableList.of(BIGINT, createVarcharType(10), VARBINARY, DOUBLE, BOOLEAN, arrayType, mapType, arrayOfArrayType); assertEquals(orcFileMetadata, new OrcFileMetadata(ImmutableMap.<Long, TypeSignature>builder() .put(1L, BIGINT.getTypeSignature()) .put(2L, createVarcharType(10).getTypeSignature()) .put(4L, VARBINARY.getTypeSignature()) .put(6L, DOUBLE.getTypeSignature())
@Test public void testCastWithJsonParseOptimization() Signature jsonParseSignature = new Signature("json_parse", SCALAR, JSON.getTypeSignature(), ImmutableList.of(VARCHAR.getTypeSignature()));
@Test public void testIOExplain() { String query = "SELECT * FROM orders"; MaterializedResult result = computeActual("EXPLAIN (TYPE IO, FORMAT JSON) " + query); TableColumnInfo input = new TableColumnInfo( new CatalogSchemaTableName("local", "sf0.01", "orders"), ImmutableSet.of( new ColumnConstraint( "orderstatus", createVarcharType(1).getTypeSignature(), new FormattedDomain( false, ImmutableSet.of( new FormattedRange( new FormattedMarker(Optional.of("F"), EXACTLY), new FormattedMarker(Optional.of("F"), EXACTLY)), new FormattedRange( new FormattedMarker(Optional.of("O"), EXACTLY), new FormattedMarker(Optional.of("O"), EXACTLY)), new FormattedRange( new FormattedMarker(Optional.of("P"), EXACTLY), new FormattedMarker(Optional.of("P"), EXACTLY))))))); assertEquals( jsonCodec(IOPlan.class).fromJson((String) getOnlyElement(result.getOnlyColumnAsSet())), new IOPlan(ImmutableSet.of(input), Optional.empty())); } }