use of io.crate.metadata.ColumnIdent in project crate by crate.
the class SortSymbolVisitor method visitReference.
/**
* generate a SortField from a Reference symbol.
* <p>
* the implementation is similar to what {@link org.elasticsearch.search.sort.SortParseElement}
* does.
*/
@Override
public SortField visitReference(final Reference symbol, final SortSymbolContext context) {
// can't use the SortField(fieldName, type) constructor
// because values are saved using docValues and therefore they're indexed in lucene as binary and not
// with the reference valueType.
// this is why we use a custom comparator source with the same logic as ES
ColumnIdent columnIdent = symbol.ident().columnIdent();
if (columnIdent.isColumn()) {
if (SortParseElement.SCORE_FIELD_NAME.equals(columnIdent.name())) {
return !context.reverseFlag ? SORT_SCORE_REVERSE : SortParseElement.SORT_SCORE;
} else if (DocSysColumns.RAW.equals(columnIdent) || DocSysColumns.ID.equals(columnIdent)) {
return customSortField(DocSysColumns.nameForLucene(columnIdent), symbol, context, LUCENE_TYPE_MAP.get(symbol.valueType()), false);
}
}
MultiValueMode sortMode = context.reverseFlag ? MultiValueMode.MAX : MultiValueMode.MIN;
String indexName;
IndexFieldData.XFieldComparatorSource fieldComparatorSource;
MappedFieldType fieldType = fieldTypeLookup.get(columnIdent.fqn());
if (fieldType == null) {
indexName = columnIdent.fqn();
fieldComparatorSource = new NullFieldComparatorSource(LUCENE_TYPE_MAP.get(symbol.valueType()), context.reverseFlag, context.nullFirst);
} else {
indexName = fieldType.names().indexName();
fieldComparatorSource = context.context.fieldData().getForField(fieldType).comparatorSource(SortOrder.missing(context.reverseFlag, context.nullFirst), sortMode, null);
}
return new SortField(indexName, fieldComparatorSource, context.reverseFlag);
}
use of io.crate.metadata.ColumnIdent in project crate by crate.
the class WriterProjectionTest method testStreaming.
@Test
public void testStreaming() throws Exception {
WriterProjection p = new WriterProjection(ImmutableList.<Symbol>of(new InputColumn(1)), Literal.of("/foo.json"), WriterProjection.CompressionType.GZIP, MapBuilder.<ColumnIdent, Symbol>newMapBuilder().put(new ColumnIdent("partitionColumn"), Literal.of(1)).map(), ImmutableList.of("foo"), WriterProjection.OutputFormat.JSON_OBJECT);
BytesStreamOutput out = new BytesStreamOutput();
Projection.toStream(p, out);
StreamInput in = StreamInput.wrap(out.bytes());
WriterProjection p2 = (WriterProjection) Projection.fromStream(in);
assertEquals(p, p2);
}
use of io.crate.metadata.ColumnIdent in project crate by crate.
the class BlobTableInfoTest method testGetColumnInfo.
@Test
public void testGetColumnInfo() throws Exception {
Reference foobar = info.getReference(new ColumnIdent("digest"));
assertNotNull(foobar);
assertEquals(DataTypes.STRING, foobar.valueType());
}
use of io.crate.metadata.ColumnIdent in project crate by crate.
the class SysNodesExpressionsWithDefaultExtendedStatsTest method testFsDataOnNonDataNode.
@Test
public void testFsDataOnNonDataNode() throws Exception {
prepare(false);
Reference refInfo = refInfo("sys.nodes.fs", DataTypes.STRING, RowGranularity.NODE, "data");
ColumnIdent columnIdent = refInfo.ident().columnIdent();
NestedObjectExpression fs = (NestedObjectExpression) resolver.getChildImplementation(columnIdent.name());
assertThat(((Object[]) fs.getChildImplementation(columnIdent.path().get(0)).value()).length, is(0));
}
use of io.crate.metadata.ColumnIdent in project crate by crate.
the class FetchContextTest method testSearcherIsAcquiredForShard.
@Test
public void testSearcherIsAcquiredForShard() throws Exception {
Routing routing = new Routing(TreeMapBuilder.<String, Map<String, List<Integer>>>newMapBuilder().put("dummy", TreeMapBuilder.<String, List<Integer>>newMapBuilder().put("i1", ImmutableList.of(1, 2)).map()).map());
IndexBaseVisitor ibv = new IndexBaseVisitor();
routing.walkLocations(ibv);
HashMultimap<TableIdent, String> tableIndices = HashMultimap.create();
tableIndices.put(new TableIdent(null, "i1"), "i1");
final FetchContext context = new FetchContext(new FetchPhase(1, null, ibv.build(), tableIndices, ImmutableList.of(createReference("i1", new ColumnIdent("x"), DataTypes.STRING))), "dummy", new SharedShardContexts(mock(IndicesService.class, RETURNS_MOCKS)), ImmutableList.of(routing));
context.prepare();
assertThat(context.searcher(1), Matchers.notNullValue());
assertThat(context.searcher(2), Matchers.notNullValue());
}
Aggregations