use of io.crate.metadata.ReferenceIdent in project crate by crate.
the class TransportAnalyzeActionTest method test_create_stats_for_tables_with_array_columns_with_nulls.
@Test
public void test_create_stats_for_tables_with_array_columns_with_nulls() {
var rows = new ArrayList<String>();
rows.add(null);
var samples = new Samples(List.of(new Row1(rows), new Row1(rows)), List.of(DataTypes.STRING_ARRAY.streamer()), 2, SizeEstimatorFactory.create(DataTypes.STRING_ARRAY).estimateSize(rows));
var references = List.of(new Reference(new ReferenceIdent(new RelationName(Schemas.DOC_SCHEMA_NAME, "dummy"), "dummy"), RowGranularity.DOC, DataTypes.STRING_ARRAY, 0, null));
var stats = TransportAnalyzeAction.createTableStats(samples, references);
assertThat(stats.numDocs, is(2L));
}
use of io.crate.metadata.ReferenceIdent in project crate by crate.
the class DocTableInfo method getDynamic.
@Nullable
public DynamicReference getDynamic(ColumnIdent ident, boolean forWrite, boolean errorOnUnknownObjectKey) {
boolean parentIsIgnored = false;
ColumnPolicy parentPolicy = columnPolicy();
int position = 0;
if (!ident.isTopLevel()) {
// see if parent is strict object
ColumnIdent parentIdent = ident.getParent();
Reference parentInfo = null;
while (parentIdent != null) {
parentInfo = getReference(parentIdent);
if (parentInfo != null) {
break;
}
parentIdent = parentIdent.getParent();
}
if (parentInfo != null) {
parentPolicy = parentInfo.columnPolicy();
position = parentInfo.position();
}
}
switch(parentPolicy) {
case DYNAMIC:
if (!forWrite) {
if (!errorOnUnknownObjectKey) {
return new VoidReference(new ReferenceIdent(ident(), ident), rowGranularity(), position);
}
return null;
}
break;
case STRICT:
if (forWrite) {
throw new ColumnUnknownException(ident.sqlFqn(), ident());
}
return null;
case IGNORED:
parentIsIgnored = true;
break;
default:
break;
}
if (parentIsIgnored) {
return new DynamicReference(new ReferenceIdent(ident(), ident), rowGranularity(), ColumnPolicy.IGNORED, position);
}
return new DynamicReference(new ReferenceIdent(ident(), ident), rowGranularity(), position);
}
use of io.crate.metadata.ReferenceIdent in project crate by crate.
the class ValueNormalizerTest method testNormalizePrimitiveLiteral.
@Test
public void testNormalizePrimitiveLiteral() throws Exception {
Reference ref = new Reference(new ReferenceIdent(TEST_TABLE_IDENT, new ColumnIdent("bool")), RowGranularity.DOC, DataTypes.BOOLEAN, 0, null);
Literal<Boolean> trueLiteral = Literal.of(true);
assertThat(normalizeInputForReference(trueLiteral, ref), Matchers.<Symbol>is(trueLiteral));
assertThat(normalizeInputForReference(Literal.of("true"), ref), Matchers.<Symbol>is(trueLiteral));
assertThat(normalizeInputForReference(Literal.of("false"), ref), Matchers.<Symbol>is(Literal.of(false)));
}
use of io.crate.metadata.ReferenceIdent in project crate by crate.
the class IndexWriterProjectorTest method testIndexWriter.
@Test
public void testIndexWriter() throws Throwable {
execute("create table bulk_import (id int primary key, name string) with (number_of_replicas=0)");
ensureGreen();
InputCollectExpression sourceInput = new InputCollectExpression(1);
List<CollectExpression<Row, ?>> collectExpressions = Collections.<CollectExpression<Row, ?>>singletonList(sourceInput);
RelationName bulkImportIdent = new RelationName(sqlExecutor.getCurrentSchema(), "bulk_import");
ClusterState state = clusterService().state();
Settings tableSettings = TableSettingsResolver.get(state.getMetadata(), bulkImportIdent, false);
ThreadPool threadPool = internalCluster().getInstance(ThreadPool.class);
IndexWriterProjector writerProjector = new IndexWriterProjector(clusterService(), new NodeLimits(new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)), new NoopCircuitBreaker("dummy"), RamAccounting.NO_ACCOUNTING, threadPool.scheduler(), threadPool.executor(ThreadPool.Names.SEARCH), CoordinatorTxnCtx.systemTransactionContext(), new NodeContext(internalCluster().getInstance(Functions.class)), Settings.EMPTY, IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING.get(tableSettings), NumberOfReplicas.fromSettings(tableSettings, state.getNodes().getSize()), internalCluster().getInstance(TransportCreatePartitionsAction.class), internalCluster().getInstance(TransportShardUpsertAction.class)::execute, IndexNameResolver.forTable(bulkImportIdent), new Reference(new ReferenceIdent(bulkImportIdent, DocSysColumns.RAW), RowGranularity.DOC, DataTypes.STRING, 0, null), Collections.singletonList(ID_IDENT), Collections.<Symbol>singletonList(new InputColumn(0)), null, null, sourceInput, collectExpressions, 20, null, null, false, false, UUID.randomUUID(), UpsertResultContext.forRowCount(), false);
BatchIterator rowsIterator = InMemoryBatchIterator.of(IntStream.range(0, 100).mapToObj(i -> new RowN(new Object[] { i, "{\"id\": " + i + ", \"name\": \"Arthur\"}" })).collect(Collectors.toList()), SENTINEL, true);
TestingRowConsumer consumer = new TestingRowConsumer();
consumer.accept(writerProjector.apply(rowsIterator), null);
Bucket objects = consumer.getBucket();
assertThat(objects, contains(isRow(100L)));
execute("refresh table bulk_import");
execute("select count(*) from bulk_import");
assertThat(response.rowCount(), is(1L));
assertThat(response.rows()[0][0], is(100L));
}
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 ByteBuffersDirectory(), new IndexWriterConfig(new StandardAnalyzer()));
dummyShardId = new ShardId("dummy", UUIDs.randomBase64UUID(), 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, true));
collectorContext = new CollectorContext();
reference = new Reference(new ReferenceIdent(new RelationName(Schemas.DOC_SCHEMA_NAME, "dummyTable"), columnName), RowGranularity.DOC, DataTypes.INTEGER, 1, null);
orderBy = new OrderBy(Collections.singletonList(reference), reverseFlags, nullsFirst);
}
Aggregations