Search in sources :

Example 46 with RelationName

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);
}
Also used : RelationName(io.crate.metadata.RelationName) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) SqlExpressions(io.crate.testing.SqlExpressions) Before(org.junit.Before)

Example 47 with RelationName

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")));
}
Also used : Symbol(io.crate.expression.symbol.Symbol) RelationName(io.crate.metadata.RelationName) List(java.util.List) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 48 with RelationName

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));
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) HashMap(java.util.HashMap) SQLExecutor(io.crate.testing.SQLExecutor) ColumnStats(io.crate.statistics.ColumnStats) Stats(io.crate.statistics.Stats) TableStats(io.crate.statistics.TableStats) RelationName(io.crate.metadata.RelationName) TableStats(io.crate.statistics.TableStats) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 49 with RelationName

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;
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Symbol(io.crate.expression.symbol.Symbol) ArrayList(java.util.ArrayList) RelationName(io.crate.metadata.RelationName) TableInfo(io.crate.metadata.table.TableInfo) SysNodesTableInfo(io.crate.metadata.sys.SysNodesTableInfo) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) SqlExpressions(io.crate.testing.SqlExpressions) TableRelation(io.crate.analyze.relations.TableRelation)

Example 50 with RelationName

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);
}
Also used : Input(io.crate.data.Input) TransactionContext(io.crate.metadata.TransactionContext) SqlExpressions(io.crate.testing.SqlExpressions) Arrays(java.util.Arrays) Array(java.lang.reflect.Array) RelationName(io.crate.metadata.RelationName) SENTINEL(io.crate.data.SentinelRow.SENTINEL) BatchIterator(io.crate.data.BatchIterator) ReferenceResolver(io.crate.expression.reference.ReferenceResolver) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) RowN(io.crate.data.RowN) Map(java.util.Map) SQLExecutor(io.crate.testing.SQLExecutor) Before(org.junit.Before) DocTableInfo(io.crate.metadata.doc.DocTableInfo) User(io.crate.user.User) AbstractModule(org.elasticsearch.common.inject.AbstractModule) AggregationFunction(io.crate.execution.engine.aggregation.AggregationFunction) InMemoryBatchIterator(io.crate.data.InMemoryBatchIterator) ColumnIdent(io.crate.metadata.ColumnIdent) Comparators.createComparator(io.crate.execution.engine.sort.Comparators.createComparator) RamAccounting(io.crate.breaker.RamAccounting) Collectors(java.util.stream.Collectors) Lists2(io.crate.common.collections.Lists2) InputCollectExpression(io.crate.execution.engine.collect.InputCollectExpression) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ExpressionsInput(io.crate.expression.ExpressionsInput) List(java.util.List) OrderBy(io.crate.analyze.OrderBy) BatchIterators(io.crate.data.BatchIterators) Version(org.elasticsearch.Version) DocTableRelation(io.crate.analyze.relations.DocTableRelation) Row(io.crate.data.Row) Literal(io.crate.expression.symbol.Literal) Symbol(io.crate.expression.symbol.Symbol) FunctionImplementation(io.crate.metadata.FunctionImplementation) Matcher(org.hamcrest.Matcher) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) InputColumns(io.crate.execution.dsl.projection.builder.InputColumns) OnHeapMemoryManager(io.crate.memory.OnHeapMemoryManager) InputFactory(io.crate.expression.InputFactory) Comparator(java.util.Comparator) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) InputFactory(io.crate.expression.InputFactory) DocTableInfo(io.crate.metadata.doc.DocTableInfo) OnHeapMemoryManager(io.crate.memory.OnHeapMemoryManager) RelationName(io.crate.metadata.RelationName) DocTableRelation(io.crate.analyze.relations.DocTableRelation) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) SqlExpressions(io.crate.testing.SqlExpressions) Before(org.junit.Before)

Aggregations

RelationName (io.crate.metadata.RelationName)180 Test (org.junit.Test)100 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)55 PartitionName (io.crate.metadata.PartitionName)47 Symbol (io.crate.expression.symbol.Symbol)42 Reference (io.crate.metadata.Reference)37 ColumnIdent (io.crate.metadata.ColumnIdent)31 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)21 ReferenceIdent (io.crate.metadata.ReferenceIdent)21 DocTableInfo (io.crate.metadata.doc.DocTableInfo)21 Map (java.util.Map)20 HashMap (java.util.HashMap)19 SqlExpressions (io.crate.testing.SqlExpressions)18 ArrayList (java.util.ArrayList)18 List (java.util.List)17 Before (org.junit.Before)17 DocTableRelation (io.crate.analyze.relations.DocTableRelation)13 SQLExecutor (io.crate.testing.SQLExecutor)11 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)10 IndexTemplateMetadata (org.elasticsearch.cluster.metadata.IndexTemplateMetadata)10