Search in sources :

Example 1 with ReferenceImplementation

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

Example 2 with ReferenceImplementation

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

Example 3 with ReferenceImplementation

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

Example 4 with ReferenceImplementation

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

Example 5 with ReferenceImplementation

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);
}
Also used : HashMap(java.util.HashMap) RowCollectExpression(io.crate.metadata.RowCollectExpression) Map(java.util.Map) HashMap(java.util.HashMap) BytesRef(org.apache.lucene.util.BytesRef) ReferenceImplementation(io.crate.metadata.ReferenceImplementation)

Aggregations

ReferenceImplementation (io.crate.metadata.ReferenceImplementation)8 CrateUnitTest (io.crate.test.integration.CrateUnitTest)5 BytesRef (org.apache.lucene.util.BytesRef)5 Test (org.junit.Test)5 Reference (io.crate.metadata.Reference)3 RowCollectExpression (io.crate.metadata.RowCollectExpression)1 ExtendedOsStats (io.crate.monitor.ExtendedOsStats)1 NestedObjectExpression (io.crate.operation.reference.NestedObjectExpression)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Nullable (javax.annotation.Nullable)1