use of io.crate.metadata.RelationName in project crate by crate.
the class HashJoinConditionSymbolsExtractorTest method prepare.
@Before
public void prepare() throws Exception {
Map<RelationName, AnalyzedRelation> sources = T3.sources(clusterService);
sqlExpressions = new SqlExpressions(sources);
tr1 = sources.get(T3.T1);
tr2 = sources.get(T3.T2);
}
use of io.crate.metadata.RelationName in project crate by crate.
the class HashJoinConditionSymbolsExtractorTest method testExtractSymbolsWithDuplicates.
@Test
public void testExtractSymbolsWithDuplicates() {
Symbol joinCondition = sqlExpressions.asSymbol("t1.a = t2.b and t1.i + 1::int = t2.i and t2.y = t1.i + 1::int");
Map<RelationName, List<Symbol>> symbolsPerRelation = HashJoinConditionSymbolsExtractor.extract(joinCondition);
assertThat(symbolsPerRelation.get(tr1.relationName()), containsInAnyOrder(isReference("a"), isFunction(ArithmeticFunctions.Names.ADD, isReference("i"), isLiteral(1))));
assertThat(symbolsPerRelation.get(tr2.relationName()), containsInAnyOrder(isReference("b"), isReference("i")));
}
use of io.crate.metadata.RelationName 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.metadata.RelationName in project crate by crate.
the class NodeStatsCollectSourceTest method filterNodes.
private List<DiscoveryNode> filterNodes(String where) throws NoSuchFieldException, IllegalAccessException {
// build where clause with id = ?
TableInfo tableInfo = SysNodesTableInfo.create();
TableRelation tableRelation = new TableRelation(tableInfo);
Map<RelationName, AnalyzedRelation> tableSources = Map.of(tableInfo.ident(), tableRelation);
SqlExpressions sqlExpressions = new SqlExpressions(tableSources, tableRelation);
Symbol query = sqlExpressions.normalize(sqlExpressions.asSymbol(where));
List<DiscoveryNode> nodes = new ArrayList<>(NodeStatsCollectSource.filterNodes(discoveryNodes, query, sqlExpressions.nodeCtx));
nodes.sort(Comparator.comparing(DiscoveryNode::getId));
return nodes;
}
use of io.crate.metadata.RelationName in project crate by crate.
the class AbstractWindowFunctionTest method prepareFunctions.
@Before
public void prepareFunctions() {
DocTableInfo tableInfo = SQLExecutor.tableInfo(new RelationName("doc", "t1"), "create table doc.t1 (x int, y bigint, z string, d double)", clusterService);
DocTableRelation tableRelation = new DocTableRelation(tableInfo);
Map<RelationName, AnalyzedRelation> tableSources = Map.of(tableInfo.ident(), tableRelation);
memoryManager = new OnHeapMemoryManager(bytes -> {
});
sqlExpressions = new SqlExpressions(tableSources, tableRelation, User.CRATE_USER, additionalModules);
inputFactory = new InputFactory(sqlExpressions.nodeCtx);
}
Aggregations