use of io.crate.analyze.relations.DocTableRelation in project crate by crate.
the class WhereClauseOptimizerTest method optimize.
private WhereClauseOptimizer.DetailedQuery optimize(String statement) {
QueriedSelectRelation queriedTable = e.analyze(statement);
DocTableRelation table = ((DocTableRelation) queriedTable.from().get(0));
EvaluatingNormalizer normalizer = new EvaluatingNormalizer(e.nodeCtx, RowGranularity.CLUSTER, null, table);
return WhereClauseOptimizer.optimize(normalizer, queriedTable.where(), table.tableInfo(), e.getPlannerContext(clusterService.state()).transactionContext(), e.nodeCtx);
}
use of io.crate.analyze.relations.DocTableRelation in project crate by crate.
the class EqualityExtractorTest method test_primary_key_extraction_on_subscript_with_any.
@Test
public void test_primary_key_extraction_on_subscript_with_any() {
Map<RelationName, AnalyzedRelation> sources = T3.sources(List.of(T3.T4), clusterService);
DocTableRelation tr4 = (DocTableRelation) sources.get(T3.T4);
var expressionsT4 = new SqlExpressions(sources, tr4);
var pkCol = new ColumnIdent("obj");
var query = expressionsT4.normalize(expressionsT4.asSymbol("obj = any([{i = 1}])"));
List<List<Symbol>> matches = analyzeExact(query, List.of(pkCol));
assertThat(matches, contains(contains(isLiteral(Map.of("i", 1)))));
}
use of io.crate.analyze.relations.DocTableRelation in project crate by crate.
the class SelectStatementAnalyzerTest method test_match_with_geo_shape_is_streamed_as_text_type_to_4_1_8_nodes.
@Test
public void test_match_with_geo_shape_is_streamed_as_text_type_to_4_1_8_nodes() throws Exception {
var executor = SQLExecutor.builder(clusterService).addTable("create table test (shape GEO_SHAPE)").build();
String stmt = "SELECT * FROM test WHERE MATCH (shape, 'POINT(1.2 1.3)')";
QueriedSelectRelation rel = executor.analyze(stmt);
Symbol where = rel.where();
assertThat(where, instanceOf(MatchPredicate.class));
DocTableInfo table = executor.resolveTableInfo("test");
EvaluatingNormalizer normalizer = new EvaluatingNormalizer(executor.nodeCtx, RowGranularity.DOC, null, new DocTableRelation(table));
Symbol normalized = normalizer.normalize(where, CoordinatorTxnCtx.systemTransactionContext());
assertThat(normalized, isFunction("match"));
Function match = (Function) normalized;
assertThat(match.arguments().get(1).valueType(), is(DataTypes.GEO_SHAPE));
assertThat(match.info().ident().argumentTypes().get(1), is(DataTypes.GEO_SHAPE));
BytesStreamOutput out = new BytesStreamOutput();
out.setVersion(Version.V_4_1_8);
match.writeTo(out);
StreamInput in = out.bytes().streamInput();
in.setVersion(Version.V_4_1_8);
Function serializedTo41 = new Function(in);
assertThat(serializedTo41.info().ident().argumentTypes().get(1), is(DataTypes.STRING));
}
use of io.crate.analyze.relations.DocTableRelation in project crate by crate.
the class GeneratedReferenceTest method prepare.
@Before
public void prepare() throws Exception {
executor = SQLExecutor.builder(clusterService).addTable(T1_DEFINITION).build();
t1Info = executor.schemas().getTableInfo(T1);
DocTableRelation tableRelation = new DocTableRelation(t1Info);
// allocate field so it can be resolved
tableRelation.getField(new ColumnIdent("a"));
expressions = new SqlExpressions(Collections.emptyMap(), tableRelation);
}
use of io.crate.analyze.relations.DocTableRelation in project crate by crate.
the class CopyAnalyzer method convertCopyFrom.
CopyFromAnalyzedStatement convertCopyFrom(CopyFrom node, Analysis analysis) {
DocTableInfo tableInfo = schemas.getWritableTable(TableIdent.of(node.table(), analysis.sessionContext().defaultSchema()));
DocTableRelation tableRelation = new DocTableRelation(tableInfo);
Operation.blockedRaiseException(tableInfo, Operation.INSERT);
String partitionIdent = null;
if (!node.table().partitionProperties().isEmpty()) {
partitionIdent = PartitionPropertiesAnalyzer.toPartitionIdent(tableInfo, node.table().partitionProperties(), analysis.parameterContext().parameters());
}
EvaluatingNormalizer normalizer = new EvaluatingNormalizer(functions, RowGranularity.CLUSTER, ReplaceMode.MUTATE, null, tableRelation);
ExpressionAnalyzer expressionAnalyzer = createExpressionAnalyzer(analysis, tableRelation);
expressionAnalyzer.setResolveFieldsOperation(Operation.INSERT);
ExpressionAnalysisContext expressionAnalysisContext = new ExpressionAnalysisContext();
Predicate<DiscoveryNode> nodeFilters = Predicates.alwaysTrue();
Settings settings = Settings.EMPTY;
if (node.genericProperties().isPresent()) {
// copy map as items are removed. The GenericProperties map is cached in the query cache and removing
// items would cause subsequent queries that hit the cache to have different genericProperties
Map<String, Expression> properties = new HashMap<>(node.genericProperties().get().properties());
nodeFilters = discoveryNodePredicate(analysis.parameterContext().parameters(), properties.remove(NodeFilters.NAME));
settings = settingsFromProperties(properties, expressionAnalyzer, expressionAnalysisContext);
}
Symbol uri = expressionAnalyzer.convert(node.path(), expressionAnalysisContext);
uri = normalizer.normalize(uri, analysis.transactionContext());
if (!(uri.valueType() == DataTypes.STRING || uri.valueType() instanceof CollectionType && ((CollectionType) uri.valueType()).innerType() == DataTypes.STRING)) {
throw CopyFromAnalyzedStatement.raiseInvalidType(uri.valueType());
}
return new CopyFromAnalyzedStatement(tableInfo, settings, uri, partitionIdent, nodeFilters);
}
Aggregations