DecimalType decimalType = (DecimalType) type; if (isNull) { return NullableValue.asNull(decimalType); return NullableValue.of(decimalType, 0L); return NullableValue.of(decimalType, shortDecimalPartitionKey(value, decimalType, partitionName)); return NullableValue.of(decimalType, Decimals.encodeUnscaledValue(BigInteger.ZERO)); return NullableValue.of(decimalType, longDecimalPartitionKey(value, decimalType, partitionName)); return NullableValue.asNull(BOOLEAN); return NullableValue.of(BOOLEAN, false); return NullableValue.of(BOOLEAN, booleanPartitionKey(value, partitionName)); return NullableValue.asNull(TINYINT); return NullableValue.of(TINYINT, 0L); return NullableValue.of(TINYINT, tinyintPartitionKey(value, partitionName)); return NullableValue.asNull(SMALLINT); return NullableValue.of(SMALLINT, 0L); return NullableValue.of(SMALLINT, smallintPartitionKey(value, partitionName));
private Optional<Expression> coerceComparisonWithRounding( Type symbolExpressionType, Expression symbolExpression, NullableValue nullableValue, ComparisonExpression.Operator comparisonOperator) { requireNonNull(nullableValue, "nullableValue is null"); if (nullableValue.isNull()) { return Optional.empty(); } Type valueType = nullableValue.getType(); Object value = nullableValue.getValue(); return floorValue(valueType, symbolExpressionType, value) .map((floorValue) -> rewriteComparisonExpression(symbolExpressionType, symbolExpression, valueType, value, floorValue, comparisonOperator)); }
/** * Convert a map of columns to values into the TupleDomain which requires * those columns to be fixed to those values. Null is allowed as a fixed value. */ public static <T> TupleDomain<T> fromFixedValues(Map<T, NullableValue> fixedValues) { return TupleDomain.withColumnDomains(fixedValues.entrySet().stream() .collect(toMap( Map.Entry::getKey, entry -> { Type type = entry.getValue().getType(); Object value = entry.getValue().getValue(); return value == null ? Domain.onlyNull(type) : Domain.singleValue(type, value); }))); }
@Override public ConnectorSplitSource getSplits(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorTableLayoutHandle layout, SplitSchedulingStrategy splitSchedulingStrategy) { JmxTableLayoutHandle jmxLayout = (JmxTableLayoutHandle) layout; JmxTableHandle tableHandle = jmxLayout.getTable(); TupleDomain<ColumnHandle> predicate = jmxLayout.getConstraint(); //TODO is there a better way to get the node column? Optional<JmxColumnHandle> nodeColumnHandle = tableHandle.getColumnHandles().stream() .filter(jmxColumnHandle -> jmxColumnHandle.getColumnName().equals(NODE_COLUMN_NAME)) .findFirst(); checkState(nodeColumnHandle.isPresent(), "Failed to find %s column", NODE_COLUMN_NAME); List<ConnectorSplit> splits = nodeManager.getAllNodes().stream() .filter(node -> { NullableValue value = NullableValue.of(createUnboundedVarcharType(), utf8Slice(node.getNodeIdentifier())); return predicate.overlaps(fromFixedValues(ImmutableMap.of(nodeColumnHandle.get(), value))); }) .map(node -> new JmxSplit(tableHandle, ImmutableList.of(node.getHostAndPort()))) .collect(toList()); return new FixedSplitSource(splits); } }
public static NullableValue asNull(Type type) { return new NullableValue(type, null); }
@VisibleForTesting static long calculateDistinctPartitionKeys( HiveColumnHandle column, List<HivePartition> partitions) { return partitions.stream() .map(partition -> partition.getKeys().get(column)) .filter(value -> !value.isNull()) .distinct() .count(); }
@Test public void testCreateOnlyNullsPredicate() { ImmutableList.Builder<HivePartition> partitions = ImmutableList.builder(); for (int i = 0; i < 5; i++) { partitions.add(new HivePartition( new SchemaTableName("test", "test"), Integer.toString(i), ImmutableMap.of(TEST_COLUMN_HANDLE, NullableValue.asNull(VarcharType.VARCHAR)))); } createPredicate(ImmutableList.of(TEST_COLUMN_HANDLE), partitions.build()); }
.map(argument -> { if (argument.isConstant()) { return argument.getConstant().getType();
private boolean rowMatchesPredicate() { if (predicate.isAll()) { return true; } if (predicate.isNone()) { return false; } Map<ColumnHandle, NullableValue> rowMap = predicate.getDomains().get().keySet().stream() .collect(toImmutableMap( column -> column, column -> { TpchColumnHandle tpchColumnHandle = (TpchColumnHandle) column; Type type = tpchColumnHandle.getType(); TpchColumn tpchColumn = table.getColumn(tpchColumnHandle.getColumnName()); return NullableValue.of(type, getPrestoObject(tpchColumn, type)); })); TupleDomain<ColumnHandle> rowTupleDomain = TupleDomain.fromFixedValues(rowMap); return predicate.contains(rowTupleDomain); }
public static NullableValue of(Type type, Object value) { requireNonNull(value, "value is null"); return new NullableValue(type, value); }
@VisibleForTesting static Optional<DoubleRange> calculateRangeForPartitioningKey(HiveColumnHandle column, Type type, List<HivePartition> partitions) { if (!isRangeSupported(type)) { return Optional.empty(); } List<Double> values = partitions.stream() .map(HivePartition::getKeys) .map(keys -> keys.get(column)) .filter(value -> !value.isNull()) .map(NullableValue::getValue) .map(value -> convertPartitionValueToDouble(type, value)) .collect(toImmutableList()); if (values.isEmpty()) { return Optional.empty(); } double min = values.get(0); double max = values.get(0); for (Double value : values) { if (value > max) { max = value; } if (value < min) { min = value; } } return Optional.of(new DoubleRange(min, max)); }
@Test public void testCreateOnlyNullsPredicate() { ImmutableList.Builder<HivePartition> partitions = ImmutableList.builder(); for (int i = 0; i < 5; i++) { partitions.add(new HivePartition( new SchemaTableName("test", "test"), Integer.toString(i), ImmutableMap.of(TEST_COLUMN_HANDLE, NullableValue.asNull(VarcharType.VARCHAR)))); } createPredicate(ImmutableList.of(TEST_COLUMN_HANDLE), partitions.build()); }
.map(argument -> { if (argument.isConstant()) { return argument.getConstant().getType();
public static NullableValue getColumnValueForPartitionKey(Row row, int i, CassandraType cassandraType, List<CassandraType> typeArguments) { Type nativeType = cassandraType.getNativeType(); if (row.isNull(i)) { return NullableValue.asNull(nativeType); } switch (cassandraType) { case ASCII: case TEXT: case VARCHAR: return NullableValue.of(nativeType, utf8Slice(row.getString(i))); case UUID: case TIMEUUID: return NullableValue.of(nativeType, utf8Slice(row.getUUID(i).toString())); default: return getColumnValue(row, i, cassandraType, typeArguments); } }
private boolean rowMatchesPredicate() { if (predicate.isAll()) { return true; } if (predicate.isNone()) { return false; } Map<ColumnHandle, NullableValue> rowMap = predicate.getDomains().get().keySet().stream() .collect(toImmutableMap( column -> column, column -> { TpchColumnHandle tpchColumnHandle = (TpchColumnHandle) column; Type type = tpchColumnHandle.getType(); TpchColumn tpchColumn = table.getColumn(tpchColumnHandle.getColumnName()); return NullableValue.of(type, getPrestoObject(tpchColumn, type)); })); TupleDomain<ColumnHandle> rowTupleDomain = TupleDomain.fromFixedValues(rowMap); return predicate.contains(rowTupleDomain); }
@Override public Object getValue(Symbol symbol) { ColumnHandle column = assignments.get(symbol); checkArgument(column != null, "Missing column assignment for %s", symbol); if (!bindings.containsKey(column)) { return symbol.toSymbolReference(); } return bindings.get(column).getValue(); } }