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();
}
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();
}
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);
}
}
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());
}
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;
}
Aggregations