use of io.crate.metadata.ReferenceIdent in project crate by crate.
the class LuceneReferenceResolverTest method testGetImplementationWithColumnsOfTypeCollection.
@Test
public void testGetImplementationWithColumnsOfTypeCollection() {
Reference arrayRef = new Reference(new ReferenceIdent(new TableIdent("s", "t"), "a"), RowGranularity.DOC, DataTypes.DOUBLE_ARRAY);
assertThat(luceneReferenceResolver.getImplementation(arrayRef), instanceOf(DocCollectorExpression.ChildDocCollectorExpression.class));
Reference setRef = new Reference(new ReferenceIdent(new TableIdent("s", "t"), "a"), RowGranularity.DOC, new SetType(DataTypes.DOUBLE));
assertThat(luceneReferenceResolver.getImplementation(setRef), instanceOf(DocCollectorExpression.ChildDocCollectorExpression.class));
}
use of io.crate.metadata.ReferenceIdent in project crate by crate.
the class OrderedLuceneBatchIteratorBenchmark method createLuceneBatchIterator.
@Setup
public void createLuceneBatchIterator() throws Exception {
IndexWriter iw = new IndexWriter(new RAMDirectory(), new IndexWriterConfig(new StandardAnalyzer()));
dummyShardId = new ShardId("dummy", 1);
columnName = "x";
for (int i = 0; i < 10_000_000; i++) {
Document doc = new Document();
doc.add(new NumericDocValuesField(columnName, i));
iw.addDocument(doc);
}
iw.commit();
iw.forceMerge(1, true);
indexSearcher = new IndexSearcher(DirectoryReader.open(iw, true));
collectorContext = new CollectorContext(mock(IndexFieldDataService.class), new CollectorFieldsVisitor(0));
fieldTypeLookup = column -> {
IntegerFieldMapper.IntegerFieldType integerFieldType = new IntegerFieldMapper.IntegerFieldType();
integerFieldType.setNames(new MappedFieldType.Names(column));
return integerFieldType;
};
reference = new Reference(new ReferenceIdent(new TableIdent(null, "dummyTable"), columnName), RowGranularity.DOC, DataTypes.INTEGER);
orderBy = new OrderBy(Collections.singletonList(reference), reverseFlags, nullsFirst);
}
use of io.crate.metadata.ReferenceIdent in project crate by crate.
the class NodeStatsIteratorTest method prepare.
@Before
public void prepare() {
idRef = new Reference(new ReferenceIdent(SysNodesTableInfo.IDENT, SysNodesTableInfo.Columns.ID), RowGranularity.DOC, DataTypes.STRING);
nameRef = new Reference(new ReferenceIdent(SysNodesTableInfo.IDENT, SysNodesTableInfo.Columns.ID), RowGranularity.DOC, DataTypes.STRING);
hostnameRef = new Reference(new ReferenceIdent(SysNodesTableInfo.IDENT, SysNodesTableInfo.Columns.HOSTNAME), RowGranularity.DOC, DataTypes.STRING);
collectPhase = mock(RoutedCollectPhase.class);
when(collectPhase.whereClause()).thenReturn(WhereClause.NO_MATCH);
nodes.add(newNode("nodeOne"));
nodes.add(newNode("nodeTwo"));
}
use of io.crate.metadata.ReferenceIdent in project crate by crate.
the class AnalyzedTableElements method buildReference.
private static <T> void buildReference(RelationName relationName, AnalyzedColumnDefinition<T> columnDefinition, List<Reference> references) {
Reference reference;
DataType<?> type = columnDefinition.dataType() == null ? DataTypes.UNDEFINED : columnDefinition.dataType();
DataType<?> realType = ArrayType.NAME.equals(columnDefinition.collectionType()) ? new ArrayType<>(type) : type;
if (columnDefinition.isGenerated() == false) {
reference = new Reference(new ReferenceIdent(relationName, columnDefinition.ident()), RowGranularity.DOC, realType, columnDefinition.position, // not required in this context
null);
} else {
reference = new GeneratedReference(columnDefinition.position, new ReferenceIdent(relationName, columnDefinition.ident()), RowGranularity.DOC, realType, "dummy expression, real one not needed here");
}
references.add(reference);
for (AnalyzedColumnDefinition<T> childDefinition : columnDefinition.children()) {
buildReference(relationName, childDefinition, references);
}
}
use of io.crate.metadata.ReferenceIdent in project crate by crate.
the class InternalViewInfoFactory method create.
@Override
public ViewInfo create(RelationName ident, ClusterState state) {
ViewsMetadata meta = state.metadata().custom(ViewsMetadata.TYPE);
if (meta == null) {
return null;
}
ViewMetadata view = meta.getView(ident);
if (view == null) {
return null;
}
List<Reference> columns;
try {
AnalyzedRelation relation = analyzerProvider.get().analyze((Query) SqlParser.createStatement(view.stmt()), CoordinatorTxnCtx.systemTransactionContext(), ParamTypeHints.EMPTY);
final List<Reference> collectedColumns = new ArrayList<>(relation.outputs().size());
int position = 1;
for (var field : relation.outputs()) {
collectedColumns.add(new Reference(new ReferenceIdent(ident, Symbols.pathFromSymbol(field).sqlFqn()), RowGranularity.DOC, field.valueType(), position++, null));
}
columns = collectedColumns;
} catch (Exception e) {
if (e instanceof ResourceUnknownException) {
// Return ViewInfo with no columns in case the statement could not be analyzed,
// because the underlying table of the view could not be found.
columns = Collections.emptyList();
} else {
throw e;
}
}
return new ViewInfo(ident, view.stmt(), columns, view.owner());
}
Aggregations