use of io.crate.types.RowType in project crate by crate.
the class PGTypesTest method test_can_retrieve_pg_type_for_record_array.
@Test
public void test_can_retrieve_pg_type_for_record_array() throws Exception {
var pgType = PGTypes.get(new ArrayType<>(new RowType(List.of(DataTypes.STRING))));
assertThat(pgType.oid(), is(PGArray.EMPTY_RECORD_ARRAY.oid()));
byte[] bytes = pgType.encodeAsUTF8Text(List.of(new Row1("foobar")));
assertThat(new String(bytes, StandardCharsets.UTF_8), is("{\"(foobar)\"}"));
}
use of io.crate.types.RowType in project crate by crate.
the class SubscriptFunctionsTest method test_subscript_can_be_created_for_accessing_field_within_nested_record.
@Test
public void test_subscript_can_be_created_for_accessing_field_within_nested_record() throws Exception {
var rowType = new RowType(List.of(new RowType(List.of(DataTypes.INTEGER), List.of("y"))), List.of("x"));
var rowExpression = Literal.of(rowType, new Row1(new Row1(10)));
var subscript = SubscriptFunctions.tryCreateSubscript(rowExpression, List.of("x", "y"));
assertThat(subscript, isFunction("_subscript_record", isFunction("_subscript_record"), isLiteral("y")));
}
use of io.crate.types.RowType in project crate by crate.
the class TableFunctionCollectSource method getIterator.
@Override
@SuppressWarnings("unchecked")
public CompletableFuture<BatchIterator<Row>> getIterator(TransactionContext txnCtx, CollectPhase collectPhase, CollectTask collectTask, boolean supportMoveToStart) {
TableFunctionCollectPhase phase = (TableFunctionCollectPhase) collectPhase;
TableFunctionImplementation<?> functionImplementation = phase.functionImplementation();
RowType rowType = functionImplementation.returnType();
// noinspection unchecked Only literals can be passed to table functions. Anything else is invalid SQL
List<Input<?>> inputs = (List<Input<?>>) (List<?>) phase.functionArguments();
List<Input<?>> topLevelInputs = new ArrayList<>(phase.toCollect().size());
List<String> columns = rowType.fieldNames();
InputFactory.Context<InputCollectExpression> ctx = inputFactory.ctxForRefs(txnCtx, ref -> {
for (int i = 0; i < columns.size(); i++) {
String column = columns.get(i);
if (ref.column().isTopLevel() && ref.column().name().equals(column)) {
return new InputCollectExpression(i);
}
}
throw new IllegalStateException("Column `" + ref + "` not found in " + functionImplementation.signature().getName().displayName());
});
for (Symbol symbol : phase.toCollect()) {
topLevelInputs.add(ctx.add(symbol));
}
var inputRow = new ValueAndInputRow<>(topLevelInputs, ctx.expressions());
Input<Boolean> condition = (Input<Boolean>) ctx.add(phase.where());
Iterable<Row> rows = () -> StreamSupport.stream(functionImplementation.evaluate(txnCtx, nodeCtx, inputs.toArray(new Input[0])).spliterator(), false).map(inputRow).filter(InputCondition.asPredicate(condition)).iterator();
return CompletableFuture.completedFuture(InMemoryBatchIterator.of(rows, SentinelRow.SENTINEL, functionImplementation.hasLazyResultSet()));
}
use of io.crate.types.RowType in project crate by crate.
the class SizeEstimatorFactoryTest method test_estimate_size_of_record.
@Test
public void test_estimate_size_of_record() throws Exception {
var estimator = SizeEstimatorFactory.create(new RowType(List.of(DataTypes.LONG, DataTypes.INTEGER)));
assertThat(estimator.estimateSize(new RowN(20L, 10)), is(40L));
}
Aggregations