use of io.crate.metadata.ColumnIdent in project crate by crate.
the class AlterTableAddColumnAnalyzerTest method testAddNewNestedObjectColumn.
@Test
public void testAddNewNestedObjectColumn() throws Exception {
AddColumnAnalyzedStatement analysis = e.analyze("alter table users add column foo['x']['y'] string");
// id pk column is also added
assertThat(analysis.analyzedTableElements().columns().size(), is(2));
AnalyzedColumnDefinition column = analysis.analyzedTableElements().columns().get(0);
assertThat(column.ident(), Matchers.equalTo(new ColumnIdent("foo")));
assertThat(column.children().size(), is(1));
AnalyzedColumnDefinition xColumn = column.children().get(0);
assertThat(xColumn.ident(), Matchers.equalTo(new ColumnIdent("foo", Arrays.asList("x"))));
assertThat(xColumn.children().size(), is(1));
AnalyzedColumnDefinition yColumn = xColumn.children().get(0);
assertThat(yColumn.ident(), Matchers.equalTo(new ColumnIdent("foo", Arrays.asList("x", "y"))));
assertThat(yColumn.children().size(), is(0));
Map<String, Object> mapping = analysis.analyzedTableElements().toMapping();
Map foo = (Map) StringObjectMaps.getByPath(mapping, "properties.foo");
assertThat((String) foo.get("type"), is("object"));
Map x = (Map) StringObjectMaps.getByPath(mapping, "properties.foo.properties.x");
assertThat((String) x.get("type"), is("object"));
Map y = (Map) StringObjectMaps.getByPath(mapping, "properties.foo.properties.x.properties.y");
assertThat((String) y.get("type"), is("string"));
}
use of io.crate.metadata.ColumnIdent in project crate by crate.
the class ESFieldExtractorTest method testNullInList.
@Test
public void testNullInList() throws Exception {
ESFieldExtractor.Source ex = new ESFieldExtractor.Source(new ColumnIdent("top", "child1"), new ArrayType(DataTypes.INTEGER));
// test null value in list
HashMap<String, Object> nullMap = new HashMap<String, Object>(1);
nullMap.put("child1", null);
ImmutableMap<String, Object> source = ImmutableMap.<String, Object>of("top", ImmutableList.of(nullMap, ImmutableMap.of("child1", 33)));
Object[] objects = (Object[]) ex.toValue(source);
assertThat(objects[0], nullValue());
assertThat(((Integer) objects[1]), is(33));
}
use of io.crate.metadata.ColumnIdent in project crate by crate.
the class ESFieldExtractorTest method testPath3.
@Test
public void testPath3() throws Exception {
ColumnIdent ci = new ColumnIdent("a", ImmutableList.of("b", "c"));
ESFieldExtractor.Source ex = new ESFieldExtractor.Source(ci, DataTypes.INTEGER);
Map<String, Object> source;
source = ImmutableMap.<String, Object>of("a", ImmutableMap.of("b", ImmutableMap.of("c", 1)));
assertEquals(1, ex.toValue(source));
source = ImmutableMap.<String, Object>of("a", ImmutableMap.of("b", ImmutableMap.of("d", 1)));
assertEquals(null, ex.toValue(source));
source = ImmutableMap.<String, Object>of("a", ImmutableMap.of("b", ImmutableMap.of("c", 1, "d", 2)));
assertEquals(1, ex.toValue(source));
}
use of io.crate.metadata.ColumnIdent in project crate by crate.
the class MapSideDataCollectOperationTest method testFileUriCollect.
@Test
public void testFileUriCollect() throws Exception {
ClusterService clusterService = new NoopClusterService();
Functions functions = getFunctions();
CollectSourceResolver collectSourceResolver = mock(CollectSourceResolver.class);
when(collectSourceResolver.getService(any(RoutedCollectPhase.class))).thenReturn(new FileCollectSource(functions, clusterService, Collections.<String, FileInputFactory>emptyMap()));
MapSideDataCollectOperation collectOperation = new MapSideDataCollectOperation(collectSourceResolver, threadPool);
File tmpFile = temporaryFolder.newFile("fileUriCollectOperation.json");
try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(tmpFile), StandardCharsets.UTF_8)) {
writer.write("{\"name\": \"Arthur\", \"id\": 4, \"details\": {\"age\": 38}}\n");
writer.write("{\"id\": 5, \"name\": \"Trillian\", \"details\": {\"age\": 33}}\n");
}
FileUriCollectPhase collectNode = new FileUriCollectPhase(UUID.randomUUID(), 0, "test", Collections.singletonList("noop_id"), Literal.of(Paths.get(tmpFile.toURI()).toUri().toString()), Arrays.<Symbol>asList(createReference("name", DataTypes.STRING), createReference(new ColumnIdent("details", "age"), DataTypes.INTEGER)), Collections.emptyList(), null, false);
String threadPoolName = JobCollectContext.threadPoolName(collectNode, "noop_id");
TestingBatchConsumer consumer = new TestingBatchConsumer();
JobCollectContext jobCollectContext = mock(JobCollectContext.class);
CrateCollector collectors = collectOperation.createCollector(collectNode, consumer, jobCollectContext);
collectOperation.launchCollector(collectors, threadPoolName);
assertThat(new CollectionBucket(consumer.getResult()), contains(isRow("Arthur", 38), isRow("Trillian", 33)));
}
Aggregations