use of io.crate.testing.SQLExecutor in project crate by crate.
the class SelectivityFunctionsCalculationTest method test_collect_operator_adapts_expected_row_count_based_on_selectivity_calculation.
@Test
public void test_collect_operator_adapts_expected_row_count_based_on_selectivity_calculation() throws Throwable {
var columnStats = new HashMap<ColumnIdent, ColumnStats>();
long totalNumRows = 20000;
var numbers = IntStream.range(1, 20001).boxed().collect(Collectors.toList());
columnStats.put(new ColumnIdent("x"), ColumnStats.fromSortedValues(numbers, DataTypes.INTEGER, 0, totalNumRows));
Stats stats = new Stats(totalNumRows, DataTypes.INTEGER.fixedSize(), columnStats);
TableStats tableStats = new TableStats();
tableStats.updateTableStats(Map.of(new RelationName("doc", "tbl"), stats));
SQLExecutor e = SQLExecutor.builder(clusterService).setTableStats(tableStats).addTable("create table doc.tbl (x int)").build();
LogicalPlan plan = e.logicalPlan("select * from doc.tbl where x = 10");
assertThat(plan.numExpectedRows(), Matchers.is(1L));
}
use of io.crate.testing.SQLExecutor in project crate by crate.
the class OptimizerTest method test_like_on_numeric_columns_keeps_cast_around_reference.
@Test
public void test_like_on_numeric_columns_keeps_cast_around_reference() throws Exception {
SQLExecutor e = SQLExecutor.builder(clusterService).addTable("create table tbl (x int)").build();
Symbol symbol = Optimizer.optimizeCasts(e.asSymbol("x like 10"), e.getPlannerContext(clusterService.state()));
assertThat(symbol, SymbolMatchers.isFunction("op_like", SymbolMatchers.isFunction("_cast"), SymbolMatchers.isLiteral("10")));
}
use of io.crate.testing.SQLExecutor in project crate by crate.
the class ColumnsIterableTest method prepare.
@Before
public void prepare() throws Exception {
SQLExecutor e = SQLExecutor.builder(clusterService).addTable(T1_DEFINITION).addTable(T4_DEFINITION).build();
t1Info = e.resolveTableInfo(T1.fqn());
t4Info = e.resolveTableInfo(T4.fqn());
}
use of io.crate.testing.SQLExecutor in project crate by crate.
the class BatchPortalTest method testEachStatementReceivesCorrectParams.
@Test
public void testEachStatementReceivesCorrectParams() throws Throwable {
SQLExecutor sqlExecutor = SQLExecutor.builder(clusterService).addTable("create table t1 (x int)").build();
Plan insertPlan = new Plan() {
@Override
public StatementType type() {
return StatementType.INSERT;
}
@Override
public void executeOrFail(DependencyCarrier executor, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) {
consumer.accept(InMemoryBatchIterator.of(params, null), null);
}
};
Planner planner = new Planner(Settings.EMPTY, clusterService, sqlExecutor.nodeCtx, new TableStats(), null, null, sqlExecutor.schemas(), new StubUserManager(), mock(SessionSettingRegistry.class)) {
@Override
public Plan plan(AnalyzedStatement analyzedStatement, PlannerContext plannerContext) {
return insertPlan;
}
};
DependencyCarrier executor = mock(DependencyCarrier.class, Answers.RETURNS_MOCKS);
Session session = new Session(sqlExecutor.nodeCtx, sqlExecutor.analyzer, planner, new JobsLogs(() -> false), false, executor, AccessControl.DISABLED, SessionContext.systemSessionContext());
session.parse("S_1", "insert into t1(x) values(1)", Collections.emptyList());
session.bind("Portal", "S_1", Collections.emptyList(), null);
final ArrayList<Object[]> s1Rows = new ArrayList<>();
session.execute("Portal", 0, new BaseResultReceiver() {
@Override
public void setNextRow(Row row) {
s1Rows.add(row.materialize());
}
});
session.parse("S_2", "insert into t1(x) values(?)", Collections.emptyList());
session.bind("Portal", "S_2", Collections.singletonList(2), null);
final ArrayList<Object[]> s2Rows = new ArrayList<>();
session.execute("Portal", 0, new BaseResultReceiver() {
@Override
public void setNextRow(Row row) {
s2Rows.add(row.materialize());
}
});
session.sync().get(5, TimeUnit.SECONDS);
assertThat(s1Rows, contains(emptyArray()));
assertThat(s2Rows, contains(arrayContaining(is(2))));
}
use of io.crate.testing.SQLExecutor in project crate by crate.
the class PostgresWireProtocolTest method prepare.
@Before
public void prepare() throws Exception {
SQLExecutor e = SQLExecutor.builder(clusterService).addTable("create table users (name text not null)").build();
sqlOperations = new SQLOperations(e.nodeCtx, e.analyzer, e.planner, () -> mock(DependencyCarrier.class), new JobsLogs(() -> true), Settings.EMPTY, clusterService, USER_MANAGER_PROVIDER) {
@Override
public Session createSession(@Nullable String defaultSchema, @Nullable User user) {
Session session = super.createSession(defaultSchema, user);
sessions.add(session);
return session;
}
};
}
Aggregations