@Override public String getDisplayName() { if (length == UNBOUNDED_LENGTH) { return getTypeSignature().getBase(); } return getTypeSignature().toString(); }
typeSignature = createUnboundedVarcharType().getTypeSignature();
return VarcharType.createUnboundedVarcharType().getTypeSignature();
@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)")); }
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"); }
@Test public void testMap() { TypeManager typeManager = new TypeRegistry(); // associate typeManager with a function registry new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig()); Type type = typeManager.getParameterizedType(StandardTypes.MAP, ImmutableList.of( TypeSignatureParameter.of(VARCHAR.getTypeSignature()), TypeSignatureParameter.of(BIGINT.getTypeSignature()))); Block expected = AccumuloRowSerializer.getBlockFromMap(type, ImmutableMap.of("a", 1L, "b", 2L, "c", 3L)); Field f1 = new Field(expected, type); assertEquals(f1.getMap(), expected); assertEquals(f1.getObject(), expected); assertEquals(f1.getType(), type); assertEquals(f1.toString(), "MAP(ARRAY ['a','b','c'], ARRAY [1,2,3])"); }
@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); } }
@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)); }
@Test public void testMap() throws Exception { TypeManager typeManager = new TypeRegistry(); // associate typeManager with a function registry new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig()); AccumuloRowSerializer serializer = serializerClass.getConstructor().newInstance(); Type type = typeManager.getParameterizedType(StandardTypes.MAP, ImmutableList.of( TypeSignatureParameter.of(VARCHAR.getTypeSignature()), TypeSignatureParameter.of(BIGINT.getTypeSignature()))); Map<Object, Object> expected = ImmutableMap.of("a", 1L, "b", 2L, "3", 3L); byte[] data = serializer.encode(type, AccumuloRowSerializer.getBlockFromMap(type, expected)); Map<Object, Object> actual = serializer.decode(type, data); assertEquals(actual, expected); deserializeData(serializer, data); actual = AccumuloRowSerializer.getMapFromBlock(type, serializer.getMap(COLUMN_NAME, type)); assertEquals(actual, expected); }
@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()));
@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())); } }
@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); }
@Inject public HiveTableProperties(TypeManager typeManager, HiveClientConfig config) { tableProperties = ImmutableList.of( new PropertyMetadata<>( STORAGE_FORMAT_PROPERTY, "Hive storage format for the table", VARCHAR, HiveStorageFormat.class, config.getHiveStorageFormat(), false, value -> HiveStorageFormat.valueOf(((String) value).toUpperCase(ENGLISH))), new PropertyMetadata<>( PARTITIONED_BY_PROPERTY, "Partition columns", typeManager.getParameterizedType(ARRAY, ImmutableList.of(VARCHAR.getTypeSignature()), ImmutableList.of()), List.class, ImmutableList.of(), false, value -> ImmutableList.copyOf(((List<String>) value).stream() .map(name -> name.toLowerCase(ENGLISH)) .collect(Collectors.toList())))); }
@Inject public TransactionsSystemTable(TypeManager typeManager, TransactionManager transactionManager) { this.transactionsTable = tableMetadataBuilder(TRANSACTIONS_TABLE_NAME) .column("transaction_id", VARCHAR) .column("isolation_level", VARCHAR) .column("read_only", BOOLEAN) .column("auto_commit_context", BOOLEAN) .column("create_time", TIMESTAMP) .column("idle_time_secs", BIGINT) .column("written_catalog", VARCHAR) .column("catalogs", typeManager.getParameterizedType(ARRAY, ImmutableList.of(VARCHAR.getTypeSignature()), ImmutableList.of())) .build(); this.transactionManager = requireNonNull(transactionManager, "transactionManager is null"); }
@Override protected RowExpression visitGenericLiteral(GenericLiteral node, Void context) { Type type = typeManager.getType(parseTypeSignature(node.getType())); if (type == null) { throw new IllegalArgumentException("Unsupported type: " + node.getType()); } if (JSON.equals(type)) { return call( new Signature("json_parse", SCALAR, types.get(node).getTypeSignature(), VARCHAR.getTypeSignature()), types.get(node), constant(utf8Slice(node.getValue()), VARCHAR)); } return call( castSignature(types.get(node), VARCHAR), types.get(node), constant(utf8Slice(node.getValue()), VARCHAR)); }
@Test public void testResolveCalculatedTypes() { // given function(varchar(x), varchar(y)):boolean Signature function = new Signature( "function", SCALAR, ImmutableList.of(), BooleanType.BOOLEAN.getTypeSignature(), ImmutableList.of(varcharX, varcharY), false); TypeSignature varchar42 = createVarcharType(42).getTypeSignature(); TypeSignature varchar44 = createVarcharType(44).getTypeSignature(); TypeSignature varchar = new TypeSignature(StandardTypes.VARCHAR, ImmutableList.of()); assertEquals( function.resolveCalculatedTypes(ImmutableList.of(varchar42, varchar44)).getArgumentTypes(), ImmutableList.of(varchar42, varchar44)); assertEquals( function.resolveCalculatedTypes(ImmutableList.of(UNKNOWN.getTypeSignature(), varchar44)).getArgumentTypes(), ImmutableList.of(varchar, varchar44)); }
@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())); } }