Search in sources :

Example 1 with ColumnIdent

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);
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) IndexFieldData(org.elasticsearch.index.fielddata.IndexFieldData) SortField(org.apache.lucene.search.SortField) MultiValueMode(org.elasticsearch.search.MultiValueMode)

Example 2 with ColumnIdent

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);
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) InputColumn(io.crate.analyze.symbol.InputColumn) StreamInput(org.elasticsearch.common.io.stream.StreamInput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 3 with ColumnIdent

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());
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) Reference(io.crate.metadata.Reference) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 4 with ColumnIdent

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));
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) Reference(io.crate.metadata.Reference) NestedObjectExpression(io.crate.operation.reference.NestedObjectExpression) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 5 with ColumnIdent

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());
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) SharedShardContexts(io.crate.action.job.SharedShardContexts) FetchPhase(io.crate.planner.node.fetch.FetchPhase) IndexBaseVisitor(io.crate.planner.fetch.IndexBaseVisitor) Routing(io.crate.metadata.Routing) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) TableIdent(io.crate.metadata.TableIdent) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

ColumnIdent (io.crate.metadata.ColumnIdent)34 Reference (io.crate.metadata.Reference)15 CrateUnitTest (io.crate.test.integration.CrateUnitTest)12 Test (org.junit.Test)12 Map (java.util.Map)5 ColumnUnknownException (io.crate.exceptions.ColumnUnknownException)4 GeneratedReference (io.crate.metadata.GeneratedReference)4 NestedObjectExpression (io.crate.operation.reference.NestedObjectExpression)3 TestingHelpers.mapToSortedString (io.crate.testing.TestingHelpers.mapToSortedString)3 ArrayType (io.crate.types.ArrayType)3 HashMap (java.util.HashMap)3 Field (io.crate.analyze.symbol.Field)2 Symbol (io.crate.analyze.symbol.Symbol)2 ColumnValidationException (io.crate.exceptions.ColumnValidationException)2 DocTableInfo (io.crate.metadata.doc.DocTableInfo)2 FileUriCollectPhase (io.crate.planner.node.dql.FileUriCollectPhase)2 DataType (io.crate.types.DataType)2 BytesRef (org.apache.lucene.util.BytesRef)2 MappedFieldType (org.elasticsearch.index.mapper.MappedFieldType)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1