use of io.crate.metadata.TableIdent 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.TableIdent in project crate by crate.
the class AlterBlobTableAnalyzer method analyze.
public AlterBlobTableAnalyzedStatement analyze(AlterBlobTable node, Row parameters) {
TableIdent tableIdent = tableToIdent(node.table());
assert BlobSchemaInfo.NAME.equals(tableIdent.schema()) : "schema name must be 'blob'";
BlobTableInfo tableInfo = (BlobTableInfo) schemas.getTableInfo(tableIdent);
TableParameter tableParameter = new TableParameter();
if (node.genericProperties().isPresent()) {
TablePropertiesAnalyzer.analyze(tableParameter, tableInfo.tableParameterInfo(), node.genericProperties(), parameters);
} else if (!node.resetProperties().isEmpty()) {
TablePropertiesAnalyzer.analyze(tableParameter, tableInfo.tableParameterInfo(), node.resetProperties());
}
return new AlterBlobTableAnalyzedStatement(tableInfo, tableParameter);
}
use of io.crate.metadata.TableIdent in project crate by crate.
the class LuceneQueryBuilderTest method prepare.
@Before
public void prepare() throws Exception {
DocTableInfo users = TestingTableInfo.builder(new TableIdent(null, "users"), null).add("name", DataTypes.STRING).add("x", DataTypes.INTEGER).add("d", DataTypes.DOUBLE).add("d_array", new ArrayType(DataTypes.DOUBLE)).add("y_array", new ArrayType(DataTypes.LONG)).add("shape", DataTypes.GEO_SHAPE).add("point", DataTypes.GEO_POINT).build();
TableRelation usersTr = new TableRelation(users);
sources = ImmutableMap.of(new QualifiedName("users"), usersTr);
expressions = new SqlExpressions(sources, usersTr);
builder = new LuceneQueryBuilder(expressions.getInstance(Functions.class));
indexCache = mock(IndexCache.class, Answers.RETURNS_MOCKS.get());
Path tempDir = createTempDir();
Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put("path.home", tempDir).build();
Index index = new Index(users.ident().indexName());
when(indexCache.indexSettings()).thenReturn(indexSettings);
AnalysisService analysisService = createAnalysisService(indexSettings, index);
mapperService = createMapperService(index, indexSettings, analysisService);
// @formatter:off
XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("default").startObject("properties").startObject("name").field("type", "string").endObject().startObject("x").field("type", "integer").endObject().startObject("d").field("type", "double").endObject().startObject("point").field("type", "geo_point").endObject().startObject("shape").field("type", "geo_shape").endObject().startObject("d_array").field("type", "array").startObject("inner").field("type", "double").endObject().endObject().startObject("y_array").field("type", "array").startObject("inner").field("type", "integer").endObject().endObject().endObject().endObject().endObject();
// @formatter:on
mapperService.merge("default", new CompressedXContent(xContentBuilder.bytes()), MapperService.MergeReason.MAPPING_UPDATE, true);
indexFieldDataService = mock(IndexFieldDataService.class);
IndexFieldData geoFieldData = mock(IndexGeoPointFieldData.class);
when(geoFieldData.getFieldNames()).thenReturn(new MappedFieldType.Names("point"));
when(indexFieldDataService.getForField(mapperService.smartNameFieldType("point"))).thenReturn(geoFieldData);
}
use of io.crate.metadata.TableIdent in project crate by crate.
the class LuceneQueryBuilderTest method testWhereRefEqNullWithDifferentTypes.
@Test
public void testWhereRefEqNullWithDifferentTypes() throws Exception {
for (DataType type : DataTypes.PRIMITIVE_TYPES) {
DocTableInfo tableInfo = TestingTableInfo.builder(new TableIdent(null, "test_primitive"), null).add("x", type).build();
TableRelation tableRelation = new TableRelation(tableInfo);
Map<QualifiedName, AnalyzedRelation> tableSources = ImmutableMap.of(new QualifiedName(tableInfo.ident().name()), tableRelation);
SqlExpressions sqlExpressions = new SqlExpressions(tableSources, tableRelation, new Object[] { null }, SessionContext.SYSTEM_SESSION);
Query query = convert(new WhereClause(sqlExpressions.normalize(sqlExpressions.asSymbol("x = ?"))));
// must always become a MatchNoDocsQuery (empty BooleanQuery)
// string: term query with null would cause NPE
// int/numeric: rangeQuery from null to null would match all
// bool: term would match false too because of the condition in the eq query builder
assertThat(query, instanceOf(BooleanQuery.class));
assertThat(((BooleanQuery) query).clauses().size(), is(0));
}
}
use of io.crate.metadata.TableIdent in project crate by crate.
the class PartitionPropertiesAnalyzerTest method testPartitionNameFromAssignmentWithBytesRef.
@Test
public void testPartitionNameFromAssignmentWithBytesRef() throws Exception {
DocTableInfo tableInfo = TestingTableInfo.builder(new TableIdent("doc", "users"), new Routing(ImmutableMap.<String, Map<String, List<Integer>>>of())).add("name", DataTypes.STRING, null, true).addPrimaryKey("name").build();
PartitionName partitionName = PartitionPropertiesAnalyzer.toPartitionName(tableInfo, Arrays.asList(new Assignment(new QualifiedNameReference(new QualifiedName("name")), new StringLiteral("foo"))), Row.EMPTY);
assertThat(partitionName.asIndexName(), is(".partitioned.users.0426crrf"));
}
Aggregations