Search in sources :

Example 41 with ColumnHandle

use of com.facebook.presto.spi.ColumnHandle in project presto by prestodb.

the class TestJdbcQueryBuilder method testEmptyBuildSql.

@Test
public void testEmptyBuildSql() throws SQLException {
    TupleDomain<ColumnHandle> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of(columns.get(0), Domain.all(BIGINT), columns.get(1), Domain.onlyNull(DOUBLE)));
    Connection connection = database.getConnection();
    try (PreparedStatement preparedStatement = new QueryBuilder("\"").buildSql(jdbcClient, session, connection, "", "", "test_table", columns, tupleDomain, Optional.empty());
        ResultSet resultSet = preparedStatement.executeQuery()) {
        assertEquals(resultSet.next(), false);
    }
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Test(org.testng.annotations.Test)

Example 42 with ColumnHandle

use of com.facebook.presto.spi.ColumnHandle in project presto by prestodb.

the class TestJdbcQueryBuilder method testNormalBuildSql.

@Test
public void testNormalBuildSql() throws SQLException {
    TupleDomain<ColumnHandle> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.<ColumnHandle, Domain>builder().put(columns.get(0), Domain.create(SortedRangeSet.copyOf(BIGINT, ImmutableList.of(Range.equal(BIGINT, 128L), Range.equal(BIGINT, 180L), Range.equal(BIGINT, 233L), Range.lessThan(BIGINT, 25L), Range.range(BIGINT, 66L, true, 96L, true), Range.greaterThan(BIGINT, 192L))), false)).put(columns.get(1), Domain.create(SortedRangeSet.copyOf(DOUBLE, ImmutableList.of(Range.equal(DOUBLE, 200011.0), Range.equal(DOUBLE, 200014.0), Range.equal(DOUBLE, 200017.0), Range.equal(DOUBLE, 200116.5), Range.range(DOUBLE, 200030.0, true, 200036.0, true), Range.range(DOUBLE, 200048.0, true, 200099.0, true))), false)).put(columns.get(7), Domain.create(SortedRangeSet.copyOf(TINYINT, ImmutableList.of(Range.range(TINYINT, 60L, true, 70L, false), Range.range(TINYINT, 52L, true, 55L, false))), false)).put(columns.get(8), Domain.create(SortedRangeSet.copyOf(SMALLINT, ImmutableList.of(Range.range(SMALLINT, -75L, true, -68L, true), Range.range(SMALLINT, -200L, true, -100L, false))), false)).put(columns.get(9), Domain.create(SortedRangeSet.copyOf(INTEGER, ImmutableList.of(Range.equal(INTEGER, 80L), Range.equal(INTEGER, 96L), Range.lessThan(INTEGER, 0L))), false)).put(columns.get(2), Domain.create(SortedRangeSet.copyOf(BOOLEAN, ImmutableList.of(Range.equal(BOOLEAN, true))), false)).build());
    Connection connection = database.getConnection();
    try (PreparedStatement preparedStatement = new QueryBuilder("\"").buildSql(jdbcClient, session, connection, "", "", "test_table", columns, tupleDomain, Optional.empty());
        ResultSet resultSet = preparedStatement.executeQuery()) {
        ImmutableSet.Builder<Long> builder = ImmutableSet.builder();
        while (resultSet.next()) {
            builder.add((Long) resultSet.getObject("col_0"));
        }
        assertEquals(builder.build(), ImmutableSet.of(68L, 180L, 196L));
    }
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) ImmutableSet(com.google.common.collect.ImmutableSet) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Domain(com.facebook.presto.common.predicate.Domain) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) Test(org.testng.annotations.Test)

Example 43 with ColumnHandle

use of com.facebook.presto.spi.ColumnHandle in project presto by prestodb.

the class JdbcRecordSetProvider method getRecordSet.

@Override
public RecordSet getRecordSet(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorSplit split, List<? extends ColumnHandle> columns) {
    JdbcSplit jdbcSplit = (JdbcSplit) split;
    ImmutableList.Builder<JdbcColumnHandle> handles = ImmutableList.builder();
    for (ColumnHandle handle : columns) {
        handles.add((JdbcColumnHandle) handle);
    }
    return new JdbcRecordSet(jdbcClient, session, jdbcSplit, handles.build());
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) ImmutableList(com.google.common.collect.ImmutableList)

Example 44 with ColumnHandle

use of com.facebook.presto.spi.ColumnHandle in project presto by prestodb.

the class DeltaMetadata method getTableLayouts.

@Override
public List<ConnectorTableLayoutResult> getTableLayouts(ConnectorSession session, ConnectorTableHandle table, Constraint<ColumnHandle> constraint, Optional<Set<ColumnHandle>> desiredColumns) {
    DeltaTableHandle tableHandle = (DeltaTableHandle) table;
    // Split the predicate into partition column predicate and other column predicates
    // Only the partition column predicate is fully enforced. Other predicate is partially enforced (best effort).
    List<TupleDomain<ColumnHandle>> predicate = splitPredicate(constraint.getSummary());
    TupleDomain<ColumnHandle> unenforcedPredicate = predicate.get(1);
    DeltaTableLayoutHandle newDeltaTableLayoutHandle = new DeltaTableLayoutHandle(tableHandle, constraint.getSummary().transform(DeltaColumnHandle.class::cast), Optional.of(constraint.getSummary().toString(session.getSqlFunctionProperties())));
    ConnectorTableLayout newLayout = new ConnectorTableLayout(newDeltaTableLayoutHandle, Optional.empty(), constraint.getSummary(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableList.of(), Optional.empty());
    return ImmutableList.of(new ConnectorTableLayoutResult(newLayout, unenforcedPredicate));
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) ConnectorTableLayoutResult(com.facebook.presto.spi.ConnectorTableLayoutResult) ConnectorTableLayout(com.facebook.presto.spi.ConnectorTableLayout)

Example 45 with ColumnHandle

use of com.facebook.presto.spi.ColumnHandle in project presto by prestodb.

the class MongoPageSourceProvider method createPageSource.

@Override
public ConnectorPageSource createPageSource(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorSplit split, List<ColumnHandle> columns, SplitContext splitContext) {
    MongoSplit mongodbSplit = (MongoSplit) split;
    ImmutableList.Builder<MongoColumnHandle> handles = ImmutableList.builder();
    for (ColumnHandle handle : requireNonNull(columns, "columns is null")) {
        handles.add((MongoColumnHandle) handle);
    }
    return new MongoPageSource(mongoSession, mongodbSplit, handles.build());
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) ImmutableList(com.google.common.collect.ImmutableList)

Aggregations

ColumnHandle (com.facebook.presto.spi.ColumnHandle)243 ImmutableList (com.google.common.collect.ImmutableList)90 ImmutableMap (com.google.common.collect.ImmutableMap)81 Test (org.testng.annotations.Test)81 ConnectorSession (com.facebook.presto.spi.ConnectorSession)80 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)70 Constraint (com.facebook.presto.spi.Constraint)66 Map (java.util.Map)65 SchemaTableName (com.facebook.presto.spi.SchemaTableName)60 Optional (java.util.Optional)57 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)54 List (java.util.List)54 Objects.requireNonNull (java.util.Objects.requireNonNull)53 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)47 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)47 ConnectorTableLayoutHandle (com.facebook.presto.spi.ConnectorTableLayoutHandle)46 ImmutableSet (com.google.common.collect.ImmutableSet)46 TestingConnectorSession (com.facebook.presto.testing.TestingConnectorSession)43 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)42 PrestoException (com.facebook.presto.spi.PrestoException)42