private static DataType<String> varcharDataType(Optional<Integer> length, String properties) { String prefix = length.map(size -> "varchar(" + size + ")").orElse("varchar"); String suffix = properties.isEmpty() ? "" : " " + properties; VarcharType varcharType = length.map(VarcharType::createVarcharType).orElse(createUnboundedVarcharType()); return stringDataType(prefix + suffix, varcharType); }
protected AbstractPropertiesSystemTable(String tableName, TransactionManager transactionManager, Supplier<Map<ConnectorId, Map<String, PropertyMetadata<?>>>> propertySupplier) { this.tableMetadata = tableMetadataBuilder(new SchemaTableName("metadata", tableName)) .column("catalog_name", createUnboundedVarcharType()) .column("property_name", createUnboundedVarcharType()) .column("default_value", createUnboundedVarcharType()) .column("type", createUnboundedVarcharType()) .column("description", createUnboundedVarcharType()) .build(); this.transactionManager = requireNonNull(transactionManager, "transactionManager is null"); this.propertySupplier = requireNonNull(propertySupplier, "propertySupplier is null"); }
private static Block resourceGroupIdToBlock(ResourceGroupId resourceGroupId) { requireNonNull(resourceGroupId, "resourceGroupId is null"); List<String> segments = resourceGroupId.getSegments(); BlockBuilder blockBuilder = createUnboundedVarcharType().createBlockBuilder(null, segments.size()); for (String segment : segments) { createUnboundedVarcharType().writeSlice(blockBuilder, utf8Slice(segment)); } return blockBuilder.build(); }
private Map<ColumnHandle, NullableValue> asFixedValues(QualifiedObjectName objectName) { return ImmutableMap.of( CATALOG_COLUMN_HANDLE, new NullableValue(createUnboundedVarcharType(), utf8Slice(objectName.getCatalogName())), SCHEMA_COLUMN_HANDLE, new NullableValue(createUnboundedVarcharType(), utf8Slice(objectName.getSchemaName())), TABLE_NAME_COLUMN_HANDLE, new NullableValue(createUnboundedVarcharType(), utf8Slice(objectName.getObjectName()))); }
@Test public void testStringStrideDictionary() throws Exception { tester.testRoundTrip(javaStringObjectInspector, concat(ImmutableList.of("a"), Collections.nCopies(9999, "123"), ImmutableList.of("b"), Collections.nCopies(9999, "123")), createUnboundedVarcharType()); }
@Override public Slice getSlice(int field) { checkFieldType(field, createUnboundedVarcharType()); return Slices.utf8Slice(getFieldValue(field)); }
@Test public void getColumnMetadata() { assertEquals(metadata.getColumnMetadata(SESSION, NUMBERS_TABLE_HANDLE, new ExampleColumnHandle(CONNECTOR_ID, "text", createUnboundedVarcharType(), 0)), new ColumnMetadata("text", createUnboundedVarcharType())); // example connector assumes that the table handle and column handle are // properly formed, so it will return a metadata object for any // ExampleTableHandle and ExampleColumnHandle passed in. This is on because // it is not possible for the Presto Metadata system to create the handles // directly. }
private static Type getCommonSuperTypeForVarchar(VarcharType firstType, VarcharType secondType) { if (firstType.isUnbounded() || secondType.isUnbounded()) { return createUnboundedVarcharType(); } return createVarcharType(Math.max(firstType.getLength(), secondType.getLength())); }
@Test public void testGetTableHandle() { JmxTableHandle handle = metadata.getTableHandle(SESSION, RUNTIME_TABLE); assertEquals(handle.getObjectNames(), ImmutableList.of(RUNTIME_OBJECT)); List<JmxColumnHandle> columns = handle.getColumnHandles(); assertTrue(columns.contains(new JmxColumnHandle("node", createUnboundedVarcharType()))); assertTrue(columns.contains(new JmxColumnHandle("Name", createUnboundedVarcharType()))); assertTrue(columns.contains(new JmxColumnHandle("StartTime", BIGINT))); }
@Test public void testColumnMetadata() { assertEquals(exampleTable.getColumnsMetadata(), ImmutableList.of( new ColumnMetadata("a", createUnboundedVarcharType()), new ColumnMetadata("b", BIGINT))); }
@Test public void testEmptyRecord() { byte[] emptyRow = new byte[0]; DecoderTestColumnHandle column = new DecoderTestColumnHandle(0, "row1", createUnboundedVarcharType(), null, "BYTE", null, false, false, false); Set<DecoderColumnHandle> columns = ImmutableSet.of(column); RowDecoder rowDecoder = DECODER_FACTORY.create(emptyMap(), columns); Map<DecoderColumnHandle, FieldValueProvider> decodedRow = rowDecoder.decodeRow(emptyRow, null) .orElseThrow(AssertionError::new); checkIsNull(decodedRow, column); }
@Test public void testGetTableSchemaOffline() { try (Transaction transaction = newTransaction()) { ConnectorMetadata metadata = transaction.getMetadata(); Map<SchemaTableName, List<ColumnMetadata>> columns = metadata.listTableColumns(newSession(), tableOffline.toSchemaTablePrefix()); assertEquals(columns.size(), 1); Map<String, ColumnMetadata> map = uniqueIndex(getOnlyElement(columns.values()), ColumnMetadata::getName); assertPrimitiveField(map, "t_string", createUnboundedVarcharType(), false); } }
@Test public void testBuildQueryIn() { TupleDomain<ColumnHandle> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of( COL2, Domain.create(ValueSet.ofRanges(equal(createUnboundedVarcharType(), utf8Slice("hello")), equal(createUnboundedVarcharType(), utf8Slice("world"))), false))); Document query = MongoSession.buildQuery(tupleDomain); Document expected = new Document(COL2.getName(), new Document("$in", ImmutableList.of("hello", "world"))); assertEquals(query, expected); }
private static Block createVarWidthValueBlock(int positionCount, int mapSize) { Type valueType = createUnboundedVarcharType(); BlockBuilder valueBlockBuilder = valueType.createBlockBuilder(null, positionCount * mapSize); for (int i = 0; i < positionCount * mapSize; i++) { int wordLength = ThreadLocalRandom.current().nextInt(5, 10); valueType.writeSlice(valueBlockBuilder, utf8Slice(randomString(wordLength))); } return valueBlockBuilder.build(); }
private void createDummyTable(SchemaTableName tableName) { try (Transaction transaction = newTransaction()) { ConnectorSession session = newSession(); ConnectorMetadata metadata = transaction.getMetadata(); List<ColumnMetadata> columns = ImmutableList.of(new ColumnMetadata("dummy", createUnboundedVarcharType())); ConnectorTableMetadata tableMetadata = new ConnectorTableMetadata(tableName, columns, createTableProperties(TEXTFILE)); ConnectorOutputTableHandle handle = metadata.beginCreateTable(session, tableMetadata, Optional.empty()); metadata.finishCreateTable(session, handle, ImmutableList.of(), ImmutableList.of()); transaction.commit(); } }
@Test public void testBuildQuery() { TupleDomain<ColumnHandle> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of( COL1, Domain.create(ValueSet.ofRanges(range(BIGINT, 100L, false, 200L, true)), false), COL2, Domain.singleValue(createUnboundedVarcharType(), utf8Slice("a value")))); Document query = MongoSession.buildQuery(tupleDomain); Document expected = new Document() .append(COL1.getName(), new Document().append("$gt", 100L).append("$lte", 200L)) .append(COL2.getName(), new Document("$eq", "a value")); assertEquals(query, expected); }
@Test public void testGetTableSchemaOfflinePartition() { try (Transaction transaction = newTransaction()) { ConnectorMetadata metadata = transaction.getMetadata(); ConnectorTableHandle tableHandle = getTableHandle(metadata, tableOfflinePartition); ConnectorTableMetadata tableMetadata = metadata.getTableMetadata(newSession(), tableHandle); Map<String, ColumnMetadata> map = uniqueIndex(tableMetadata.getColumns(), ColumnMetadata::getName); assertPrimitiveField(map, "t_string", createUnboundedVarcharType(), false); } }
@Test public void testGetTableSchemaNotReadablePartition() { try (Transaction transaction = newTransaction()) { ConnectorMetadata metadata = transaction.getMetadata(); ConnectorTableHandle tableHandle = getTableHandle(metadata, tableNotReadable); ConnectorTableMetadata tableMetadata = metadata.getTableMetadata(newSession(), tableHandle); Map<String, ColumnMetadata> map = uniqueIndex(tableMetadata.getColumns(), ColumnMetadata::getName); assertPrimitiveField(map, "t_string", createUnboundedVarcharType(), false); } }
@Test public void testBuildQueryStringType() { TupleDomain<ColumnHandle> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of( COL1, Domain.create(ValueSet.ofRanges(range(createUnboundedVarcharType(), utf8Slice("hello"), false, utf8Slice("world"), true)), false), COL2, Domain.create(ValueSet.ofRanges(greaterThanOrEqual(createUnboundedVarcharType(), utf8Slice("a value"))), false))); Document query = MongoSession.buildQuery(tupleDomain); Document expected = new Document() .append(COL1.getName(), new Document().append("$gt", "hello").append("$lte", "world")) .append(COL2.getName(), new Document("$gte", "a value")); assertEquals(query, expected); }
@Test public void testMySqlCreatedParameterizedVarchar() { DataTypeTest.create() .addRoundTrip(stringDataType("tinytext", createVarcharType(255)), "a") .addRoundTrip(stringDataType("text", createVarcharType(65535)), "b") .addRoundTrip(stringDataType("mediumtext", createVarcharType(16777215)), "c") .addRoundTrip(stringDataType("longtext", createUnboundedVarcharType()), "d") .addRoundTrip(varcharDataType(32), "e") .addRoundTrip(varcharDataType(20000), "f") .execute(getQueryRunner(), mysqlCreateAndInsert("tpch.mysql_test_parameterized_varchar")); }