Search in sources :

Example 1 with DynamicTable

use of io.trino.plugin.pinot.query.DynamicTable in project trino by trinodb.

the class PinotMetadata method getDynamicTableColumnHandles.

private Map<String, ColumnHandle> getDynamicTableColumnHandles(PinotTableHandle pinotTableHandle) {
    checkState(pinotTableHandle.getQuery().isPresent(), "dynamic table not present");
    DynamicTable dynamicTable = pinotTableHandle.getQuery().get();
    ImmutableMap.Builder<String, ColumnHandle> columnHandlesBuilder = ImmutableMap.builder();
    for (PinotColumnHandle pinotColumnHandle : dynamicTable.getProjections()) {
        columnHandlesBuilder.put(pinotColumnHandle.getColumnName().toLowerCase(ENGLISH), pinotColumnHandle);
    }
    dynamicTable.getAggregateColumns().forEach(columnHandle -> columnHandlesBuilder.put(columnHandle.getColumnName().toLowerCase(ENGLISH), columnHandle));
    return columnHandlesBuilder.buildOrThrow();
}
Also used : ColumnHandle(io.trino.spi.connector.ColumnHandle) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) DynamicTable(io.trino.plugin.pinot.query.DynamicTable)

Example 2 with DynamicTable

use of io.trino.plugin.pinot.query.DynamicTable in project trino by trinodb.

the class TestDynamicTable method testDoubleWithScientificNotation.

@Test
public void testDoubleWithScientificNotation() {
    // Pinot recognizes double literals with scientific notation as of version 0.8.0
    String tableName = "primitive_types_table";
    String query = "SELECT string_col FROM " + tableName + " WHERE double_col = 3.5E5";
    String expected = "select \"string_col\" from primitive_types_table where (\"double_col\") = '350000.0' limit 10";
    DynamicTable dynamicTable = buildFromPql(pinotMetadata, new SchemaTableName("default", query), mockClusterInfoFetcher);
    assertEquals(extractPql(dynamicTable, TupleDomain.all(), ImmutableList.of()), expected);
}
Also used : SchemaTableName(io.trino.spi.connector.SchemaTableName) DynamicTable(io.trino.plugin.pinot.query.DynamicTable) Test(org.testng.annotations.Test)

Example 3 with DynamicTable

use of io.trino.plugin.pinot.query.DynamicTable in project trino by trinodb.

the class TestDynamicTable method testSelectNoFilter.

@Test
public void testSelectNoFilter() {
    String tableName = realtimeOnlyTable.getTableName();
    List<String> columnNames = getColumnNames(tableName);
    List<String> orderByColumns = columnNames.subList(0, 5);
    List<OrderByExpression> orderByExpressions = orderByColumns.stream().limit(4).map(columnName -> new OrderByExpression(quoteIdentifier(columnName), true)).collect(toList());
    long limit = 230;
    String query = format("select %s from %s order by %s limit %s", join(", ", columnNames), tableName, orderByColumns.stream().collect(joining(", ")) + " desc", limit);
    DynamicTable dynamicTable = buildFromPql(pinotMetadata, new SchemaTableName("default", query), mockClusterInfoFetcher);
    assertEquals(dynamicTable.getProjections().stream().map(PinotColumnHandle::getColumnName).collect(toImmutableList()), columnNames);
    orderByExpressions.add(new OrderByExpression(quoteIdentifier(orderByColumns.get(4)), false));
    assertEquals(dynamicTable.getOrderBy(), orderByExpressions);
    assertEquals(dynamicTable.getLimit().getAsLong(), limit);
}
Also used : DynamicTable(io.trino.plugin.pinot.query.DynamicTable) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) VARCHAR(io.trino.spi.type.VarcharType.VARCHAR) REALTIME_SUFFIX(io.trino.plugin.pinot.query.DynamicTableBuilder.REALTIME_SUFFIX) ImmutableList(com.google.common.collect.ImmutableList) String.join(java.lang.String.join) Slices(io.airlift.slice.Slices) ColumnHandle(io.trino.spi.connector.ColumnHandle) OrderByExpression(io.trino.plugin.pinot.query.OrderByExpression) ENGLISH(java.util.Locale.ENGLISH) ImmutableMap(com.google.common.collect.ImmutableMap) Range(io.trino.spi.predicate.Range) Domain(io.trino.spi.predicate.Domain) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) OFFLINE_SUFFIX(io.trino.plugin.pinot.query.DynamicTableBuilder.OFFLINE_SUFFIX) DynamicTablePqlExtractor.extractPql(io.trino.plugin.pinot.query.DynamicTablePqlExtractor.extractPql) TupleDomain(io.trino.spi.predicate.TupleDomain) SchemaTableName(io.trino.spi.connector.SchemaTableName) String.format(java.lang.String.format) Collectors.joining(java.util.stream.Collectors.joining) ValueSet(io.trino.spi.predicate.ValueSet) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) DynamicTableBuilder.buildFromPql(io.trino.plugin.pinot.query.DynamicTableBuilder.buildFromPql) OrderByExpression(io.trino.plugin.pinot.query.OrderByExpression) SchemaTableName(io.trino.spi.connector.SchemaTableName) DynamicTable(io.trino.plugin.pinot.query.DynamicTable) Test(org.testng.annotations.Test)

Example 4 with DynamicTable

use of io.trino.plugin.pinot.query.DynamicTable in project trino by trinodb.

the class TestDynamicTable method testLimitAndOffset.

@Test
public void testLimitAndOffset() {
    String tableName = hybridTable.getTableName();
    String tableNameWithSuffix = tableName + REALTIME_SUFFIX;
    String query = format("select * from %s limit 70, 40", tableNameWithSuffix);
    DynamicTable dynamicTable = buildFromPql(pinotMetadata, new SchemaTableName("default", query), mockClusterInfoFetcher);
    String expectedPql = format("select %s from %s limit 70, 40", getColumnNames(tableName).stream().map(TestDynamicTable::quoteIdentifier).collect(joining(", ")), tableNameWithSuffix);
    assertEquals(extractPql(dynamicTable, TupleDomain.all(), ImmutableList.of()), expectedPql);
    assertEquals(dynamicTable.getTableName(), tableName);
}
Also used : SchemaTableName(io.trino.spi.connector.SchemaTableName) DynamicTable(io.trino.plugin.pinot.query.DynamicTable) Test(org.testng.annotations.Test)

Example 5 with DynamicTable

use of io.trino.plugin.pinot.query.DynamicTable in project trino by trinodb.

the class TestDynamicTable method testQuotesInAlias.

@Test
public void testQuotesInAlias() {
    String tableName = "quotes_in_column_names";
    String tableNameWithSuffix = tableName + REALTIME_SUFFIX;
    String query = format("select non_quoted AS \"non\"\"quoted\" from %s limit 50", tableNameWithSuffix);
    DynamicTable dynamicTable = buildFromPql(pinotMetadata, new SchemaTableName("default", query), mockClusterInfoFetcher);
    String expectedPql = format("select \"non_quoted\" AS \"non\"\"quoted\" from %s limit 50", tableNameWithSuffix);
    assertEquals(extractPql(dynamicTable, TupleDomain.all(), ImmutableList.of()), expectedPql);
    assertEquals(dynamicTable.getTableName(), tableName);
}
Also used : SchemaTableName(io.trino.spi.connector.SchemaTableName) DynamicTable(io.trino.plugin.pinot.query.DynamicTable) Test(org.testng.annotations.Test)

Aggregations

DynamicTable (io.trino.plugin.pinot.query.DynamicTable)28 SchemaTableName (io.trino.spi.connector.SchemaTableName)25 Test (org.testng.annotations.Test)24 ColumnHandle (io.trino.spi.connector.ColumnHandle)4 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)1 Slices (io.airlift.slice.Slices)1 PinotColumnHandle.fromColumnMetadata (io.trino.plugin.pinot.PinotColumnHandle.fromColumnMetadata)1 AggregateExpression (io.trino.plugin.pinot.query.AggregateExpression)1 OFFLINE_SUFFIX (io.trino.plugin.pinot.query.DynamicTableBuilder.OFFLINE_SUFFIX)1 REALTIME_SUFFIX (io.trino.plugin.pinot.query.DynamicTableBuilder.REALTIME_SUFFIX)1 DynamicTableBuilder.buildFromPql (io.trino.plugin.pinot.query.DynamicTableBuilder.buildFromPql)1 DynamicTablePqlExtractor.extractPql (io.trino.plugin.pinot.query.DynamicTablePqlExtractor.extractPql)1 OrderByExpression (io.trino.plugin.pinot.query.OrderByExpression)1 PinotQueryInfo (io.trino.plugin.pinot.query.PinotQueryInfo)1 AggregateFunction (io.trino.spi.connector.AggregateFunction)1 Assignment (io.trino.spi.connector.Assignment)1 ColumnMetadata (io.trino.spi.connector.ColumnMetadata)1