Java Code Examples for io.crate.types.StringType#INSTANCE
The following examples show how to use
io.crate.types.StringType#INSTANCE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CrateDocumentConverterTest.java From spring-data-crate with Apache License 2.0 | 6 votes |
@Test public void shouldMapSimpleTypes() { String[] columns = {"string", "integer", "bool", "locale"}; DataType<?>[] types = { StringType.INSTANCE, IntegerType.INSTANCE, BooleanType.INSTANCE, StringType.INSTANCE }; Object[] row = new Object[]{"DOCUMENT", 1, true, CANADA}; Map<String, Object> expected = new HashMap<String, Object>(); expected.put("string", "DOCUMENT"); expected.put("integer", 1); expected.put("bool", true); expected.put("locale", CANADA); converter = new CrateDocumentConverter(columns, types, row); CrateDocument document = converter.toDocument(); assertThat(document, is(notNullValue())); assertThat(document.equals(expected), is(true)); }
Example 2
Source File: GeneratedReferenceTest.java From crate with Apache License 2.0 | 6 votes |
@Test public void testStreaming() throws Exception { ReferenceIdent referenceIdent = new ReferenceIdent(t1Info.ident(), "generated_column"); String formattedGeneratedExpression = "concat(a, 'bar')"; GeneratedReference generatedReferenceInfo = new GeneratedReference(null, referenceIdent, RowGranularity.DOC, StringType.INSTANCE, ColumnPolicy.STRICT, Reference.IndexType.ANALYZED, formattedGeneratedExpression, false); generatedReferenceInfo.generatedExpression(expressions.normalize(executor.asSymbol(formattedGeneratedExpression))); generatedReferenceInfo.referencedReferences(ImmutableList.of(t1Info.getReference(new ColumnIdent("a")))); BytesStreamOutput out = new BytesStreamOutput(); Reference.toStream(generatedReferenceInfo, out); StreamInput in = out.bytes().streamInput(); GeneratedReference generatedReferenceInfo2 = Reference.fromStream(in); assertThat(generatedReferenceInfo2, is(generatedReferenceInfo)); }
Example 3
Source File: IndexReferenceTest.java From crate with Apache License 2.0 | 6 votes |
@Test public void testStreaming() throws Exception { RelationName relationName = new RelationName("doc", "test"); ReferenceIdent referenceIdent = new ReferenceIdent(relationName, "string_col"); Reference reference = new Reference(referenceIdent, RowGranularity.DOC, StringType.INSTANCE, null, null); ReferenceIdent indexReferenceIdent = new ReferenceIdent(relationName, "index_column"); IndexReference indexReferenceInfo = new IndexReference( null, indexReferenceIdent, Reference.IndexType.ANALYZED, List.of(reference), "my_analyzer"); BytesStreamOutput out = new BytesStreamOutput(); Reference.toStream(indexReferenceInfo, out); StreamInput in = out.bytes().streamInput(); IndexReference indexReferenceInfo2 = Reference.fromStream(in); assertThat(indexReferenceInfo2, is(indexReferenceInfo)); }
Example 4
Source File: CrateDocumentConverterTest.java From spring-data-crate with Apache License 2.0 | 4 votes |
@Test public void shouldCreateEmptyDocument() { String[] columns = {"string"}; DataType<?>[] types = { StringType.INSTANCE }; Object[] row = new Object[0]; converter = new CrateDocumentConverter(columns, types, row); CrateDocument document = converter.toDocument(); assertThat(document, is(notNullValue())); assertThat(document.isEmpty(), is(true)); converter = new CrateDocumentConverter(columns, types, null); document = converter.toDocument(); assertThat(document, is(notNullValue())); assertThat(document.isEmpty(), is(true)); }
Example 5
Source File: CrateDocumentConverterTest.java From spring-data-crate with Apache License 2.0 | 4 votes |
@Test public void shouldMapArrayTypes() { String[] strings = {"C", "R", "A", "T", "E"}; String[] columns = {"strings"}; DataType<?>[] types = { new ArrayType(StringType.INSTANCE) }; Object[] row = new Object[]{strings}; CrateArray stringsArray = new CrateArray(); stringsArray.addAll(asList(strings)); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("strings", stringsArray); converter = new CrateDocumentConverter(columns, types, row); CrateDocument document = converter.toDocument(); assertThat(document, is(notNullValue())); assertThat(document.equals(expected), is(true)); }
Example 6
Source File: CrateDocumentConverterTest.java From spring-data-crate with Apache License 2.0 | 4 votes |
@Test @SuppressWarnings("unchecked") public void shouldMapComplexType() { Map<String, Object> languageDocument = new HashMap<String, Object>(); languageDocument.put("name", "aLanguage"); Map<String, Object> emailDocument = new HashMap<String, Object>(); emailDocument.put("email", "[email protected]"); List<Map<String, Object>> languagesArray = asList(languageDocument); List<Map<String, Object>> emailsArray = asList(emailDocument); Map<String, Object> countryDocument = new HashMap<String, Object>(); countryDocument.put("name", "aCountry"); countryDocument.put("languages", languagesArray); Map<String, Object> addressDocument = new HashMap<String, Object>(); addressDocument.put("country", countryDocument); addressDocument.put("city", "aCity"); addressDocument.put("street", "aStreet"); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("name", "aName"); expected.put("address", addressDocument); expected.put("emails", emailsArray); String[] columns = {"name", "address", "emails"}; DataType<?>[] types = { StringType.INSTANCE, ObjectType.INSTANCE, new ArrayType(ObjectType.INSTANCE) }; Object[] row = new Object[]{"aName", addressDocument, emailsArray}; converter = new CrateDocumentConverter(columns, types, row); CrateDocument document = converter.toDocument(); assertThat(document, is(notNullValue())); assertThat(document.size(), is(3)); assertThat(document.equals(expected), is(true)); }
Example 7
Source File: CrateDocumentConverterTest.java From spring-data-crate with Apache License 2.0 | 3 votes |
@Test public void shouldMapSimpleCollectionTypes() { List<String> strings = asList("C", "R", "A", "T", "E"); List<Integer> integers = asList(1, 2); String[] columns = {"strings", "integers"}; DataType<?>[] types = { new ArrayType(StringType.INSTANCE), new ArrayType(IntegerType.INSTANCE) }; Object[] row = new Object[]{strings, integers}; CrateArray stringsArray = new CrateArray(); stringsArray.addAll(strings); CrateArray integersArray = new CrateArray(); integersArray.addAll(integers); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("strings", stringsArray); expected.put("integers", integersArray); converter = new CrateDocumentConverter(columns, types, row); CrateDocument document = converter.toDocument(); assertThat(document, is(notNullValue())); assertThat(document.equals(expected), is(true)); }