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}"));
}
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));
}
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()));
}
}
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;
}
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);
}
}
Aggregations