Search in sources :

Example 21 with ColumnIdent

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

the class SysNodesExpressionsTest method testNestedBytesRefExpressionsString.

@Test
public void testNestedBytesRefExpressionsString() throws Exception {
    Reference refInfo = refInfo("sys.nodes.version", DataTypes.OBJECT, RowGranularity.NODE);
    ColumnIdent versionColIdent = refInfo.ident().columnIdent();
    io.crate.operation.reference.NestedObjectExpression version = (io.crate.operation.reference.NestedObjectExpression) resolver.getChildImplementation(versionColIdent.name());
    assertThat(version.value().get("number"), instanceOf(String.class));
}
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) NestedObjectExpression(io.crate.operation.reference.NestedObjectExpression) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 22 with ColumnIdent

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

the class FileWriterCountCollector method toNestedStringObjectMap.

@VisibleForTesting
static Map<String, Object> toNestedStringObjectMap(Map<ColumnIdent, Object> columnIdentObjectMap) {
    Map<String, Object> nestedMap = new HashMap<>();
    Map<String, Object> parent = nestedMap;
    for (Map.Entry<ColumnIdent, Object> entry : columnIdentObjectMap.entrySet()) {
        ColumnIdent key = entry.getKey();
        Object value = entry.getValue();
        if (key.path().isEmpty()) {
            nestedMap.put(key.name(), value);
        } else {
            LinkedList<String> path = new LinkedList<>(key.path());
            path.add(0, key.name());
            while (true) {
                String currentKey = path.pop();
                if (path.isEmpty()) {
                    parent.put(currentKey, value);
                    break;
                }
                Object o = parent.get(currentKey);
                if (o == null) {
                    Map<String, Object> child = new HashMap<>();
                    parent.put(currentKey, child);
                    parent = child;
                } else {
                    assert o instanceof Map : "o must be instance of Map";
                    parent = (Map) o;
                }
            }
        }
    }
    return nestedMap;
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 23 with ColumnIdent

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

the class FileLineReferenceResolver method getImplementation.

public static LineCollectorExpression<?> getImplementation(Reference refInfo) {
    ColumnIdent columnIdent = refInfo.ident().columnIdent();
    Supplier<LineCollectorExpression<?>> supplier = EXPRESSION_BUILDER.get(columnIdent.name());
    if (supplier == null) {
        return new ColumnExtractingLineExpression(columnIdent);
    }
    return supplier.get();
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) LineCollectorExpression(io.crate.operation.collect.files.LineCollectorExpression)

Example 24 with ColumnIdent

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

the class NodeStatsRequest method readFrom.

@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    columns = new HashSet<>();
    int columnIdentsSize = in.readVInt();
    for (int i = 0; i < columnIdentsSize; i++) {
        columns.add(new ColumnIdent(in));
    }
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent)

Example 25 with ColumnIdent

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

the class TableReferenceResolver method resolveField.

@Override
public Reference resolveField(QualifiedName qualifiedName, @Nullable List<String> path, Operation operation) {
    List<String> parts = qualifiedName.getParts();
    ColumnIdent columnIdent = new ColumnIdent(parts.get(parts.size() - 1), path);
    if (parts.size() != 1) {
        throw new IllegalArgumentException(String.format(Locale.ENGLISH, "Column reference \"%s\" has too many parts. " + "A column must not have a schema or a table here.", qualifiedName));
    }
    for (Reference reference : tableReferences) {
        if (reference.ident().columnIdent().equals(columnIdent)) {
            if (reference instanceof GeneratedReference) {
                throw new IllegalArgumentException("A generated column cannot be based on a generated column");
            }
            references.add(reference);
            return reference;
        }
    }
    throw new ColumnUnknownException(columnIdent.sqlFqn());
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) GeneratedReference(io.crate.metadata.GeneratedReference) ColumnUnknownException(io.crate.exceptions.ColumnUnknownException) GeneratedReference(io.crate.metadata.GeneratedReference) Reference(io.crate.metadata.Reference)

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