Search in sources :

Example 11 with Reference

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

the class LuceneReferenceResolverTest method testGetImplementationWithColumnsOfTypeCollection.

@Test
public void testGetImplementationWithColumnsOfTypeCollection() {
    Reference arrayRef = new Reference(new ReferenceIdent(new TableIdent("s", "t"), "a"), RowGranularity.DOC, DataTypes.DOUBLE_ARRAY);
    assertThat(luceneReferenceResolver.getImplementation(arrayRef), instanceOf(DocCollectorExpression.ChildDocCollectorExpression.class));
    Reference setRef = new Reference(new ReferenceIdent(new TableIdent("s", "t"), "a"), RowGranularity.DOC, new SetType(DataTypes.DOUBLE));
    assertThat(luceneReferenceResolver.getImplementation(setRef), instanceOf(DocCollectorExpression.ChildDocCollectorExpression.class));
}
Also used : SetType(io.crate.types.SetType) Reference(io.crate.metadata.Reference) TableIdent(io.crate.metadata.TableIdent) ReferenceIdent(io.crate.metadata.ReferenceIdent) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 12 with Reference

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

the class SysNodesExpressionsTest method testVersion.

@Test
public void testVersion() throws Exception {
    Reference refInfo = refInfo("sys.nodes.version", DataTypes.OBJECT, RowGranularity.NODE);
    io.crate.operation.reference.NestedObjectExpression version = (io.crate.operation.reference.NestedObjectExpression) resolver.getChildImplementation(refInfo.ident().columnIdent().name());
    Map<String, Object> v = version.value();
    assertEquals(Version.CURRENT.number(), v.get("number"));
    assertEquals(Build.CURRENT.hash(), v.get("build_hash"));
    assertEquals(Version.CURRENT.snapshot, v.get("build_snapshot"));
}
Also used : 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 13 with Reference

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

the class SysNodesExpressionsTest method testProcess.

@Test
public void testProcess() throws Exception {
    Reference refInfo = refInfo("sys.nodes.process", DataTypes.OBJECT, RowGranularity.NODE);
    io.crate.operation.reference.NestedObjectExpression processRef = (io.crate.operation.reference.NestedObjectExpression) resolver.getChildImplementation(refInfo.ident().columnIdent().name());
    Map<String, Object> v = processRef.value();
    assertEquals(42L, (long) v.get("open_file_descriptors"));
    assertEquals(1000L, (long) v.get("max_open_file_descriptors"));
    Map<String, Object> cpuObj = new HashMap<>(4);
    cpuObj.put("percent", (short) 50);
    cpuObj.put("system", 1000L);
    cpuObj.put("user", 500L);
    assertEquals(cpuObj, v.get("cpu"));
}
Also used : HashMap(java.util.HashMap) 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 14 with Reference

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

the class SysNodesExpressionsTest method testCpu.

@Test
public void testCpu() throws Exception {
    Reference refInfo = refInfo("sys.nodes.os", DataTypes.OBJECT, RowGranularity.NODE);
    io.crate.operation.reference.NestedObjectExpression os = (io.crate.operation.reference.NestedObjectExpression) resolver.getChildImplementation(refInfo.ident().columnIdent().name());
    Map<String, Object> v = os.value();
    assertEquals(3600000L, v.get("uptime"));
    Map<String, Short> cpuObj = new HashMap<>(5);
    cpuObj.put("system", (short) 0);
    cpuObj.put("user", (short) 4);
    cpuObj.put("idle", (short) 94);
    cpuObj.put("used", (short) 4);
    cpuObj.put("stolen", (short) 10);
    assertEquals(cpuObj, v.get("cpu"));
}
Also used : HashMap(java.util.HashMap) 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 15 with Reference

use of io.crate.metadata.Reference 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)

Aggregations

Reference (io.crate.metadata.Reference)84 Test (org.junit.Test)57 CrateUnitTest (io.crate.test.integration.CrateUnitTest)55 TestingHelpers.mapToSortedString (io.crate.testing.TestingHelpers.mapToSortedString)27 HashMap (java.util.HashMap)20 Map (java.util.Map)20 NestedObjectExpression (io.crate.operation.reference.NestedObjectExpression)17 ColumnIdent (io.crate.metadata.ColumnIdent)15 Symbol (io.crate.analyze.symbol.Symbol)14 BytesRef (org.apache.lucene.util.BytesRef)11 TableIdent (io.crate.metadata.TableIdent)9 ReferenceIdent (io.crate.metadata.ReferenceIdent)8 InputColumn (io.crate.analyze.symbol.InputColumn)6 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)6 ShardId (org.elasticsearch.index.shard.ShardId)5 Routing (io.crate.metadata.Routing)4 UUID (java.util.UUID)4 OrderBy (io.crate.analyze.OrderBy)3 ShardResponse (io.crate.executor.transport.ShardResponse)3 ShardUpsertRequest (io.crate.executor.transport.ShardUpsertRequest)3