use of io.crate.metadata.ReferenceImplementation in project crate by crate.
the class NodeOsExpressionTest method testOsTimestampNotEvaluatedTwice.
@Test
public void testOsTimestampNotEvaluatedTwice() throws Exception {
ExtendedOsStats osStats = mock(ExtendedOsStats.class);
NodeOsExpression nodeOsExpression = new NodeOsExpression(osStats);
ReferenceImplementation timestampExpr = nodeOsExpression.getChildImplementation("timestamp");
Long ts1 = (Long) timestampExpr.value();
Thread.sleep(10L);
Long ts2 = (Long) timestampExpr.value();
assertEquals(ts1, ts2);
}
use of io.crate.metadata.ReferenceImplementation in project crate by crate.
the class SysExpressionsBytesRefTest method testSysObjectReferenceNull.
@Test
public void testSysObjectReferenceNull() throws Exception {
NullFieldSysObjectReference nullRef = new NullFieldSysObjectReference();
ReferenceImplementation n = nullRef.getChildImplementation("n");
assertThat(n, instanceOf(BytesRefNullSysExpression.class));
Map<String, Object> value = nullRef.value();
assertThat(value.size(), is(1));
assertThat(value, hasKey("n"));
assertThat(value.get("n"), is(nullValue()));
}
use of io.crate.metadata.ReferenceImplementation in project crate by crate.
the class SysNodesExpressionsTest method testHostname.
@Test
public void testHostname() throws Exception {
Reference refInfo = refInfo("sys.nodes.hostname", DataTypes.STRING, RowGranularity.NODE);
@SuppressWarnings("unchecked") ReferenceImplementation<BytesRef> expression = (ReferenceImplementation) resolver.getChildImplementation(refInfo.ident().columnIdent().name());
BytesRef hostname = expression.value();
assertThat(hostname, notNullValue());
assertThat(InetAddresses.isInetAddress(BytesRefs.toString(hostname)), is(false));
}
use of io.crate.metadata.ReferenceImplementation in project crate by crate.
the class SysNodesExpressionsTest method testId.
@Test
public void testId() throws Exception {
Reference refInfo = refInfo("sys.nodes.id", DataTypes.STRING, RowGranularity.NODE);
@SuppressWarnings("unchecked") ReferenceImplementation<BytesRef> id = (ReferenceImplementation<BytesRef>) resolver.getChildImplementation(refInfo.ident().columnIdent().name());
assertEquals(new BytesRef("node-id-1"), id.value());
}
use of io.crate.metadata.ReferenceImplementation in project crate by crate.
the class RowCollectNestedObjectExpression method value.
@Override
public Map<String, Object> value() {
Map<String, Object> map = new HashMap<>(childImplementations.size());
for (Map.Entry<String, ReferenceImplementation> e : childImplementations.entrySet()) {
ReferenceImplementation referenceImplementation = e.getValue();
if (referenceImplementation instanceof RowCollectExpression) {
//noinspection unchecked
((RowCollectExpression) referenceImplementation).setNextRow(this.row);
}
Object value = referenceImplementation.value();
// as we do not want to convert them when building the response
if (value instanceof BytesRef) {
value = ((BytesRef) value).utf8ToString();
}
map.put(e.getKey(), value);
}
return Collections.unmodifiableMap(map);
}
Aggregations