Search in sources :

Example 1 with JDBCType

use of java.sql.JDBCType in project presto by prestodb.

the class IndexInserter method insert.

public void insert(long shardId, UUID shardUuid, OptionalInt bucketNumber, Set<Integer> nodeIds, List<ColumnStats> stats) throws SQLException {
    statement.setLong(1, shardId);
    statement.setBytes(2, uuidToBytes(shardUuid));
    if (bucketed) {
        checkArgument(bucketNumber.isPresent(), "shard bucket missing for bucketed table");
        statement.setInt(3, bucketNumber.getAsInt());
    } else {
        checkArgument(!bucketNumber.isPresent(), "shard bucket present for non-bucketed table");
        statement.setBytes(3, intArrayToBytes(nodeIds));
    }
    for (ColumnInfo column : columns) {
        int index = indexes.get(column.getColumnId());
        int type = types.get(column.getColumnId()).getVendorTypeNumber();
        statement.setNull(index, type);
        statement.setNull(index + 1, type);
    }
    for (ColumnStats column : stats) {
        int index = indexes.get(column.getColumnId());
        JDBCType type = types.get(column.getColumnId());
        bindValue(statement, type, convert(column.getMin()), index);
        bindValue(statement, type, convert(column.getMax()), index + 1);
    }
    statement.addBatch();
}
Also used : JDBCType(java.sql.JDBCType)

Example 2 with JDBCType

use of java.sql.JDBCType in project presto by prestodb.

the class ShardPredicate method createShardPredicate.

private static String createShardPredicate(ImmutableList.Builder<JDBCType> types, ImmutableList.Builder<Object> values, Domain domain, JDBCType jdbcType) {
    List<Range> ranges = domain.getValues().getRanges().getOrderedRanges();
    // only apply predicates if all ranges are single values
    if (ranges.isEmpty() || !ranges.stream().allMatch(Range::isSingleValue)) {
        return "true";
    }
    ImmutableList.Builder<Object> valuesBuilder = ImmutableList.builder();
    ImmutableList.Builder<JDBCType> typesBuilder = ImmutableList.builder();
    StringJoiner rangePredicate = new StringJoiner(" OR ");
    for (Range range : ranges) {
        Slice uuidText = (Slice) range.getSingleValue();
        try {
            Slice uuidBytes = uuidStringToBytes(uuidText);
            typesBuilder.add(jdbcType);
            valuesBuilder.add(uuidBytes);
        } catch (IllegalArgumentException e) {
            return "true";
        }
        rangePredicate.add("shard_uuid = ?");
    }
    types.addAll(typesBuilder.build());
    values.addAll(valuesBuilder.build());
    return rangePredicate.toString();
}
Also used : JDBCType(java.sql.JDBCType) ImmutableList(com.google.common.collect.ImmutableList) Slice(io.airlift.slice.Slice) Range(com.facebook.presto.spi.predicate.Range) StringJoiner(java.util.StringJoiner)

Example 3 with JDBCType

use of java.sql.JDBCType in project presto by prestodb.

the class ShardPredicate method bind.

public void bind(PreparedStatement statement) throws SQLException {
    for (int i = 0; i < types.size(); i++) {
        JDBCType type = types.get(i);
        Object value = values.get(i);
        bindValue(statement, type, value, i + 1);
    }
}
Also used : JDBCType(java.sql.JDBCType)

Example 4 with JDBCType

use of java.sql.JDBCType in project presto by prestodb.

the class ShardPredicate method create.

public static ShardPredicate create(TupleDomain<RaptorColumnHandle> tupleDomain, boolean bucketed) {
    StringJoiner predicate = new StringJoiner(" AND ").setEmptyValue("true");
    ImmutableList.Builder<JDBCType> types = ImmutableList.builder();
    ImmutableList.Builder<Object> values = ImmutableList.builder();
    for (Entry<RaptorColumnHandle, Domain> entry : tupleDomain.getDomains().get().entrySet()) {
        Domain domain = entry.getValue();
        if (domain.isNullAllowed() || domain.isAll()) {
            continue;
        }
        RaptorColumnHandle handle = entry.getKey();
        Type type = handle.getColumnType();
        JDBCType jdbcType = jdbcType(type);
        if (jdbcType == null) {
            continue;
        }
        if (handle.isShardUuid()) {
            predicate.add(createShardPredicate(types, values, domain, jdbcType));
            continue;
        }
        if (!domain.getType().isOrderable()) {
            continue;
        }
        Ranges ranges = domain.getValues().getRanges();
        // TODO: support multiple ranges
        if (ranges.getRangeCount() != 1) {
            continue;
        }
        Range range = getOnlyElement(ranges.getOrderedRanges());
        Object minValue = null;
        Object maxValue = null;
        if (range.isSingleValue()) {
            minValue = range.getSingleValue();
            maxValue = range.getSingleValue();
        } else {
            if (!range.getLow().isLowerUnbounded()) {
                minValue = range.getLow().getValue();
            }
            if (!range.getHigh().isUpperUnbounded()) {
                maxValue = range.getHigh().getValue();
            }
        }
        String min;
        String max;
        if (handle.isBucketNumber()) {
            if (!bucketed) {
                predicate.add("false");
                continue;
            }
            min = "bucket_number";
            max = "bucket_number";
        } else {
            min = minColumn(handle.getColumnId());
            max = maxColumn(handle.getColumnId());
        }
        if (minValue != null) {
            predicate.add(format("(%s >= ? OR %s IS NULL)", max, max));
            types.add(jdbcType);
            values.add(minValue);
        }
        if (maxValue != null) {
            predicate.add(format("(%s <= ? OR %s IS NULL)", min, min));
            types.add(jdbcType);
            values.add(maxValue);
        }
    }
    return new ShardPredicate(predicate.toString(), types.build(), values.build());
}
Also used : Ranges(com.facebook.presto.spi.predicate.Ranges) JDBCType(java.sql.JDBCType) RaptorColumnHandle(com.facebook.presto.raptor.RaptorColumnHandle) ImmutableList(com.google.common.collect.ImmutableList) Range(com.facebook.presto.spi.predicate.Range) JDBCType(java.sql.JDBCType) Type(com.facebook.presto.spi.type.Type) ColumnIndexStatsUtils.jdbcType(com.facebook.presto.raptor.storage.ColumnIndexStatsUtils.jdbcType) TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) Domain(com.facebook.presto.spi.predicate.Domain) StringJoiner(java.util.StringJoiner)

Example 5 with JDBCType

use of java.sql.JDBCType in project presto by prestodb.

the class ShardOrganizerUtil method getValue.

private static Object getValue(ResultSet resultSet, Type type, String columnName) throws SQLException {
    JDBCType jdbcType = jdbcType(type);
    Object value = getValue(resultSet, type, columnName, jdbcType);
    return resultSet.wasNull() ? null : value;
}
Also used : JDBCType(java.sql.JDBCType)

Aggregations

JDBCType (java.sql.JDBCType)6 Range (com.facebook.presto.spi.predicate.Range)2 ImmutableList (com.google.common.collect.ImmutableList)2 StringJoiner (java.util.StringJoiner)2 RaptorColumnHandle (com.facebook.presto.raptor.RaptorColumnHandle)1 ColumnIndexStatsUtils.jdbcType (com.facebook.presto.raptor.storage.ColumnIndexStatsUtils.jdbcType)1 Domain (com.facebook.presto.spi.predicate.Domain)1 Ranges (com.facebook.presto.spi.predicate.Ranges)1 TupleDomain (com.facebook.presto.spi.predicate.TupleDomain)1 Type (com.facebook.presto.spi.type.Type)1 Slice (io.airlift.slice.Slice)1 DataProvider (org.testng.annotations.DataProvider)1