Search in sources :

Example 6 with ColumnIdent

use of io.crate.metadata.ColumnIdent in project crate by crate.

the class SysNodesExpressionsTest method testNetworkTCP.

@Test
public void testNetworkTCP() throws Exception {
    Reference refInfo = refInfo("sys.nodes.network", DataTypes.OBJECT, RowGranularity.NODE, "tcp");
    ColumnIdent columnIdent = refInfo.ident().columnIdent();
    io.crate.operation.reference.NestedObjectExpression network = (io.crate.operation.reference.NestedObjectExpression) resolver.getChildImplementation(columnIdent.name());
    NestedObjectExpression tcpRef = (NestedObjectExpression) network.getChildImplementation(columnIdent.path().get(0));
    Map<String, Object> tcpStats = tcpRef.value();
    assertThat(tcpStats, instanceOf(Map.class));
    assertThat(mapToSortedString(tcpStats), is("connections={accepted=42, curr_established=42, dropped=42, embryonic_dropped=42, initiated=42}, " + "packets={errors_received=42, received=42, retransmitted=42, rst_sent=42, sent=42}"));
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) Reference(io.crate.metadata.Reference) TestingHelpers.mapToSortedString(io.crate.testing.TestingHelpers.mapToSortedString) NestedObjectExpression(io.crate.operation.reference.NestedObjectExpression) Map(java.util.Map) HashMap(java.util.HashMap) NestedObjectExpression(io.crate.operation.reference.NestedObjectExpression) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 7 with ColumnIdent

use of io.crate.metadata.ColumnIdent in project crate by crate.

the class ESFieldExtractorTest method testPath2.

@Test
public void testPath2() throws Exception {
    ESFieldExtractor.Source ex = new ESFieldExtractor.Source(new ColumnIdent("top", "child1"), DataTypes.INTEGER);
    Map<String, Object> source;
    source = ImmutableMap.of();
    assertNull(ex.toValue(source));
    source = ImmutableMap.<String, Object>of("top", ImmutableMap.of("child1", 1, "child2", 2));
    assertEquals(1, ex.toValue(source));
    ex = new ESFieldExtractor.Source(new ColumnIdent("top", "child1"), new ArrayType(DataTypes.INTEGER));
    source = ImmutableMap.<String, Object>of("top", ImmutableList.of(ImmutableMap.of("child1", 1), ImmutableMap.of("child1", 2), ImmutableMap.of("child2", 22)));
    assertThat((Integer) ((Object[]) ex.toValue(source))[0], is(1));
    assertThat((Integer) ((Object[]) ex.toValue(source))[1], is(2));
    // if the container is present we get an empty list instead of null, to reflect the container exitence
    source = ImmutableMap.<String, Object>of("top", ImmutableList.of(ImmutableMap.of("child2", 22), ImmutableMap.of("child3", 33)));
    assertThat(((Object[]) ex.toValue(source)).length, is(0));
    // if the container does not match -> null
    source = ImmutableMap.<String, Object>of("nomatch", ImmutableList.of(ImmutableMap.of("child2", 22), ImmutableMap.of("child3", 33)));
    assertNull(ex.toValue(source));
}
Also used : ArrayType(io.crate.types.ArrayType) ColumnIdent(io.crate.metadata.ColumnIdent) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 8 with ColumnIdent

use of io.crate.metadata.ColumnIdent in project crate by crate.

the class LuceneReferenceResolver method getImplementation.

@Override
public LuceneCollectorExpression<?> getImplementation(Reference refInfo) {
    assert refInfo.granularity() == RowGranularity.DOC : "lucene collector expressions are required to be on DOC granularity";
    ColumnIdent columnIdent = refInfo.ident().columnIdent();
    String name = columnIdent.name();
    if (RawCollectorExpression.COLUMN_NAME.equals(name)) {
        if (columnIdent.isColumn()) {
            return new RawCollectorExpression();
        } else {
            // TODO: implement an Object source expression which may support subscripts
            throw new UnsupportedFeatureException(String.format(Locale.ENGLISH, "_source expression does not support subscripts %s", columnIdent.fqn()));
        }
    } else if (UidCollectorExpression.COLUMN_NAME.equals(name)) {
        return new UidCollectorExpression();
    } else if (IdCollectorExpression.COLUMN_NAME.equals(name)) {
        return new IdCollectorExpression();
    } else if (DocCollectorExpression.COLUMN_NAME.equals(name)) {
        return DocCollectorExpression.create(refInfo);
    } else if (FetchIdCollectorExpression.COLUMN_NAME.equals(name)) {
        return new FetchIdCollectorExpression();
    } else if (ScoreCollectorExpression.COLUMN_NAME.equals(name)) {
        return new ScoreCollectorExpression();
    }
    String colName = columnIdent.fqn();
    MappedFieldType fieldType = fieldTypeLookup.get(colName);
    if (fieldType == null) {
        return new NullValueCollectorExpression(colName);
    }
    switch(refInfo.valueType().id()) {
        case ByteType.ID:
            return new ByteColumnReference(colName);
        case ShortType.ID:
            return new ShortColumnReference(colName);
        case IpType.ID:
            return new IpColumnReference(colName);
        case StringType.ID:
            return new BytesRefColumnReference(colName, fieldType);
        case DoubleType.ID:
            return new DoubleColumnReference(colName, fieldType);
        case BooleanType.ID:
            return new BooleanColumnReference(colName);
        case ObjectType.ID:
            return new ObjectColumnReference(colName);
        case FloatType.ID:
            return new FloatColumnReference(colName, fieldType);
        case LongType.ID:
        case TimestampType.ID:
            return new LongColumnReference(colName);
        case IntegerType.ID:
            return new IntegerColumnReference(colName);
        case GeoPointType.ID:
            return new GeoPointColumnReference(colName, fieldType);
        case GeoShapeType.ID:
            return new GeoShapeColumnReference(colName);
        case ArrayType.ID:
        case SetType.ID:
            return DocCollectorExpression.create(DocReferenceConverter.toSourceLookup(refInfo));
        default:
            throw new UnhandledServerException(String.format(Locale.ENGLISH, "unsupported type '%s'", refInfo.valueType().getName()));
    }
}
Also used : UnsupportedFeatureException(io.crate.exceptions.UnsupportedFeatureException) ColumnIdent(io.crate.metadata.ColumnIdent) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) UnhandledServerException(io.crate.exceptions.UnhandledServerException)

Example 9 with ColumnIdent

use of io.crate.metadata.ColumnIdent in project crate by crate.

the class GroupByConsumer method groupedByPrimaryKeys.

private static boolean groupedByPrimaryKeys(DocTableRelation tableRelation, List<Symbol> groupBy) {
    List<ColumnIdent> primaryKeys = tableRelation.tableInfo().primaryKey();
    if (groupBy.size() != primaryKeys.size()) {
        return false;
    }
    for (int i = 0, groupBySize = groupBy.size(); i < groupBySize; i++) {
        Symbol groupBySymbol = groupBy.get(i);
        if (groupBySymbol instanceof Reference) {
            ColumnIdent columnIdent = ((Reference) groupBySymbol).ident().columnIdent();
            ColumnIdent pkIdent = primaryKeys.get(i);
            if (!pkIdent.equals(columnIdent)) {
                return false;
            }
        } else {
            return false;
        }
    }
    return true;
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) Symbol(io.crate.analyze.symbol.Symbol) Reference(io.crate.metadata.Reference)

Example 10 with ColumnIdent

use of io.crate.metadata.ColumnIdent in project crate by crate.

the class NodeStatsRequest method writeTo.

@Override
public void writeTo(StreamOutput out) throws IOException {
    super.writeTo(out);
    out.writeVInt(columns.size());
    for (ColumnIdent columnIdent : columns) {
        columnIdent.writeTo(out);
    }
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent)

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