本文整理汇总了Java中org.apache.metamodel.schema.ColumnType.MAP属性的典型用法代码示例。如果您正苦于以下问题:Java ColumnType.MAP属性的具体用法?Java ColumnType.MAP怎么用?Java ColumnType.MAP使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.metamodel.schema.ColumnType
的用法示例。
在下文中一共展示了ColumnType.MAP属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rewriteColumnType
@Override
public String rewriteColumnType(ColumnType columnType, Integer columnSize) {
if (columnType == ColumnType.BLOB) {
return "bytea";
}
if (columnType == ColumnType.BIT) {
return "BOOLEAN";
}
if (columnType == ColumnType.DOUBLE) {
return "double precision";
}
if (columnType == ColumnType.MAP) {
return "jsonb";
}
return super.rewriteColumnType(columnType, columnSize);
}
示例2: getColumnType
@Override
public ColumnType getColumnType(int jdbcType, String nativeType, Integer columnSize) {
switch (nativeType) {
case "bool":
// override the normal behaviour of postgresql which maps "bool" to
// a BIT.
return ColumnType.BOOLEAN;
case "json":
case "jsonb":
return ColumnType.MAP;
}
return super.getColumnType(jdbcType, nativeType, columnSize);
}
示例3: getColumnsInternal
@Override
protected List<Column> getColumnsInternal() {
final List<Column> columnsInternal = super.getColumnsInternal();
if (columnsInternal.isEmpty() && _dataContext != null) {
try {
final org.apache.hadoop.hbase.client.Table table = _dataContext.getHTable(getName());
int columnNumber = 1;
final MutableColumn idColumn = new MutableColumn(HBaseDataContext.FIELD_ID, _defaultRowKeyColumnType)
.setPrimaryKey(true).setColumnNumber(columnNumber).setTable(this);
addColumn(idColumn);
columnNumber++;
// What about timestamp?
final HColumnDescriptor[] columnFamilies = table.getTableDescriptor().getColumnFamilies();
for (int i = 0; i < columnFamilies.length; i++) {
final HColumnDescriptor columnDescriptor = columnFamilies[i];
final String columnFamilyName = columnDescriptor.getNameAsString();
// HBase column families are always unstructured maps.
final ColumnType type = ColumnType.MAP;
final MutableColumn column = new MutableColumn(columnFamilyName, type);
column.setTable(this);
column.setColumnNumber(columnNumber);
columnNumber++;
addColumn(column);
}
} catch (Exception e) {
throw new MetaModelException("Could not resolve table ", e);
}
}
return columnsInternal;
}
示例4: getType
/**
* Determines the best fitting type. For reference of ElasticSearch types,
* see
*
* <pre>
* http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html
* </pre>
*
*
* @param column
* @return
*/
private static String getType(Column column) {
String nativeType = column.getNativeType();
if (!Strings.isNullOrEmpty(nativeType)) {
return nativeType;
}
final ColumnType type = column.getType();
if (type == null) {
throw new IllegalStateException("No column type specified for '" + column.getName()
+ "' - cannot build ElasticSearch mapping without type.");
}
if (type.isLiteral()) {
return "text";
} else if (type == ColumnType.FLOAT) {
return "float";
} else if (type == ColumnType.DOUBLE || type == ColumnType.NUMERIC || type == ColumnType.NUMBER) {
return "double";
} else if (type == ColumnType.SMALLINT) {
return "short";
} else if (type == ColumnType.TINYINT) {
return "byte";
} else if (type == ColumnType.INTEGER) {
return "integer";
} else if (type == ColumnType.DATE || type == ColumnType.TIMESTAMP) {
return "date";
} else if (type == ColumnType.BINARY || type == ColumnType.VARBINARY) {
return "binary";
} else if (type == ColumnType.BOOLEAN || type == ColumnType.BIT) {
return "boolean";
} else if (type == ColumnType.MAP) {
return "object";
}
throw new UnsupportedOperationException("Unsupported column type '" + type.getName() + "' of column '" + column
.getName() + "' - cannot translate to an ElasticSearch type.");
}
示例5: testSerializeAndDeserialize
public void testSerializeAndDeserialize() throws Exception {
final Object map1 = buildMap(
"{'some_number':1234, 'gender':'M','address':{'city':'Copenhagen','country':'DK','additional_info':null}}");
final Object map2 =
buildMap("{'some_number':5678,'gender':'M','address':{'city':'Amsterdam','countries':['NL','IN']}}");
final SimpleTableDef tableDef = new SimpleTableDef("bar", new String[] { "id", "name", "details", "bytes" },
new ColumnType[] { ColumnType.INTEGER, ColumnType.VARCHAR, ColumnType.MAP, ColumnType.BINARY });
final Collection<Object[]> arrays = new ArrayList<>();
arrays.add(new Object[] { 1, "Kasper Sørensen", map1, new byte[] { (byte) -40, (byte) -2 } });
arrays.add(new Object[] { 2, "Ankit Kumar", map2, new byte[] { (byte) 1, (byte) 3, (byte) 3, (byte) 7 } });
final TableDataProvider<?> tableProvider = new ArrayTableDataProvider(tableDef, arrays);
final List<TableDataProvider<?>> tableProviders = new ArrayList<>();
tableProviders.add(tableProvider);
PojoDatastore datastore;
datastore = new PojoDatastore("foo", tableProviders);
final JaxbPojoDatastoreAdaptor adaptor = new JaxbPojoDatastoreAdaptor(new DataCleanerConfigurationImpl());
AbstractDatastoreType serializedDatastore = adaptor.createPojoDatastore(datastore, null, 20);
final DatastoreCatalogType serializedDatastoreCatalogType = new DatastoreCatalogType();
serializedDatastoreCatalogType.getJdbcDatastoreOrAccessDatastoreOrCsvDatastore().add(serializedDatastore);
Configuration serializedConfiguration = new Configuration();
serializedConfiguration.setDatastoreCatalog(serializedDatastoreCatalogType);
// serialize and deserialize
final JAXBContext jaxbContext = JAXBContext
.newInstance(ObjectFactory.class.getPackage().getName(), ObjectFactory.class.getClassLoader());
final File file = new File("target/JaxbPojoDatastoreAdaptorTest_serialize_and_deserialize.xml");
jaxbContext.createMarshaller().marshal(serializedConfiguration, file);
serializedConfiguration = (Configuration) jaxbContext.createUnmarshaller().unmarshal(file);
serializedDatastore =
serializedConfiguration.getDatastoreCatalog().getJdbcDatastoreOrAccessDatastoreOrCsvDatastore().get(0);
datastore = adaptor.read((PojoDatastoreType) serializedDatastore);
final UpdateableDatastoreConnection con = datastore.openConnection();
final DataSet ds = con.getDataContext().query().from("bar").select("id", "name", "details").execute();
assertTrue(ds.next());
assertTrue(ds.getRow().getValue(0) instanceof Integer);
assertEquals(1, ds.getRow().getValue(0));
assertTrue(ds.getRow().getValue(1) instanceof String);
assertEquals("Kasper Sørensen", ds.getRow().getValue(1));
assertTrue(ds.getRow().getValue(2) instanceof Map);
@SuppressWarnings("unchecked") final Map<String, ?> map3 = (Map<String, ?>) ds.getRow().getValue(2);
assertEquals("{some_number=1234, gender=M, address={city=Copenhagen, country=DK, additional_info=null}}",
map3.toString());
assertEquals(Integer.class, map3.get("some_number").getClass());
assertTrue(ds.next());
assertTrue(ds.getRow().getValue(0) instanceof Integer);
assertEquals(2, ds.getRow().getValue(0));
assertTrue(ds.getRow().getValue(1) instanceof String);
assertEquals("Ankit Kumar", ds.getRow().getValue(1));
assertTrue(ds.getRow().getValue(2) instanceof Map);
@SuppressWarnings("unchecked") final Map<String, ?> map4 = (Map<String, ?>) ds.getRow().getValue(2);
assertEquals("{some_number=5678, gender=M, address={city=Amsterdam, countries=[NL, IN]}}", map4.toString());
assertEquals(Integer.class, map3.get("some_number").getClass());
assertFalse(ds.next());
assertEquals(map1, map3);
assertEquals(map2, map4);
}
示例6: getAvailableColumnTypes
private ColumnType[] getAvailableColumnTypes() {
return new ColumnType[] { ColumnType.VARCHAR, ColumnType.DECIMAL, ColumnType.INTEGER, ColumnType.BOOLEAN,
ColumnType.DATE, ColumnType.TIME, ColumnType.TIMESTAMP, ColumnType.MAP, ColumnType.LIST,
ColumnType.BINARY };
}
示例7: testSerializeAndDeserialize
public void testSerializeAndDeserialize() throws Exception {
final Object map1 = buildMap("{'some_number':1234, 'gender':'M','address':{'city':'Copenhagen','country':'DK','additional_info':null}}");
final Object map2 = buildMap("{'some_number':5678,'gender':'M','address':{'city':'Amsterdam','countries':['NL','IN']}}");
SimpleTableDef tableDef = new SimpleTableDef("bar", new String[] { "id", "name", "details", "bytes" },
new ColumnType[] { ColumnType.INTEGER, ColumnType.VARCHAR, ColumnType.MAP, ColumnType.BINARY });
Collection<Object[]> arrays = new ArrayList<Object[]>();
arrays.add(new Object[] { 1, "Kasper Sørensen", map1, new byte[] { (byte) -40, (byte) -2 } });
arrays.add(new Object[] { 2, "Ankit Kumar", map2, new byte[] { (byte) 1, (byte) 3, (byte) 3, (byte) 7 } });
TableDataProvider<?> tableProvider = new ArrayTableDataProvider(tableDef, arrays);
List<TableDataProvider<?>> tableProviders = new ArrayList<TableDataProvider<?>>();
tableProviders.add(tableProvider);
PojoDatastore datastore;
datastore = new PojoDatastore("foo", tableProviders);
final JaxbPojoDatastoreAdaptor adaptor = new JaxbPojoDatastoreAdaptor();
AbstractDatastoreType serializedDatastore = adaptor.createPojoDatastore(datastore, null, 20);
DatastoreCatalogType serializedDatastoreCatalogType = new DatastoreCatalogType();
serializedDatastoreCatalogType.getJdbcDatastoreOrAccessDatastoreOrCsvDatastore().add(serializedDatastore);
Configuration serializedConfiguration = new Configuration();
serializedConfiguration.setDatastoreCatalog(serializedDatastoreCatalogType);
// serialize and deserialize
JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class.getPackage().getName(),
ObjectFactory.class.getClassLoader());
File file = new File("target/JaxbPojoDatastoreAdaptorTest_serialize_and_deserialize.xml");
jaxbContext.createMarshaller().marshal(serializedConfiguration, file);
serializedConfiguration = (Configuration) jaxbContext.createUnmarshaller().unmarshal(file);
serializedDatastore = serializedConfiguration.getDatastoreCatalog()
.getJdbcDatastoreOrAccessDatastoreOrCsvDatastore().get(0);
datastore = adaptor.read((PojoDatastoreType) serializedDatastore);
UpdateableDatastoreConnection con = datastore.openConnection();
DataSet ds = con.getDataContext().query().from("bar").select("id", "name", "details").execute();
assertTrue(ds.next());
assertTrue(ds.getRow().getValue(0) instanceof Integer);
assertEquals(1, ds.getRow().getValue(0));
assertTrue(ds.getRow().getValue(1) instanceof String);
assertEquals("Kasper Sørensen", ds.getRow().getValue(1));
assertTrue(ds.getRow().getValue(2) instanceof Map);
@SuppressWarnings("unchecked")
final Map<String, ?> map3 = (Map<String, ?>) ds.getRow().getValue(2);
assertEquals("{some_number=1234, gender=M, address={city=Copenhagen, country=DK, additional_info=null}}",
map3.toString());
assertEquals(Integer.class, map3.get("some_number").getClass());
assertTrue(ds.next());
assertTrue(ds.getRow().getValue(0) instanceof Integer);
assertEquals(2, ds.getRow().getValue(0));
assertTrue(ds.getRow().getValue(1) instanceof String);
assertEquals("Ankit Kumar", ds.getRow().getValue(1));
assertTrue(ds.getRow().getValue(2) instanceof Map);
@SuppressWarnings("unchecked")
final Map<String, ?> map4 = (Map<String, ?>) ds.getRow().getValue(2);
assertEquals("{some_number=5678, gender=M, address={city=Amsterdam, countries=[NL, IN]}}", map4.toString());
assertEquals(Integer.class, map3.get("some_number").getClass());
assertFalse(ds.next());
assertEquals(map1, map3);
assertEquals(map2, map4);
}
示例8: testWorkingWithMapsAndLists
@Test
public void testWorkingWithMapsAndLists() throws Exception {
if (!isConfigured()) {
System.err.println(getInvalidConfigurationMessage());
return;
}
connector = couchDbInstance.createConnector("test_table_map_and_list", true);
final CouchDbDataContext dc = new CouchDbDataContext(couchDbInstance, new SimpleTableDef(
"test_table_map_and_list", new String[] { "id", "foo", "bar" }, new ColumnType[] { ColumnType.INTEGER,
ColumnType.MAP, ColumnType.LIST }));
Table table = null;
try {
table = dc.getTableByQualifiedLabel("test_table_map_and_list");
Map<String, Object> exampleMap = new LinkedHashMap<String, Object>();
exampleMap.put("hello", Arrays.asList("world", "welt", "verden"));
exampleMap.put("foo", "bar");
List<Map<String, Object>> exampleList = new ArrayList<Map<String, Object>>();
exampleList.add(new LinkedHashMap<String, Object>());
Map<String, Object> exampleMap2 = new LinkedHashMap<String, Object>();
exampleMap2.put("meta", "model");
exampleMap2.put("couch", "db");
exampleList.add(exampleMap2);
dc.executeUpdate(new InsertInto(table).value("id", 1).value("foo", exampleMap).value("bar", exampleList));
DataSet ds = dc.query().from(table).select("id", "foo", "bar").execute();
assertTrue(ds.next());
Row row = ds.getRow();
assertFalse(ds.next());
ds.close();
assertEquals("Row[values=[1, {hello=[world, welt, verden], foo=bar}, [{}, {meta=model, couch=db}]]]", row
.toString());
assertTrue(row.getValue(0) instanceof Integer);
assertTrue(row.getValue(1) instanceof Map);
assertTrue(row.getValue(2) instanceof List);
CouchDbDataContext dc2 = new CouchDbDataContext(couchDbInstance, new SimpleTableDef(
"test_table_map_and_list", new String[] { "foo.hello[0]", "bar[1].couch" }));
ds = dc2.query().from("test_table_map_and_list").select("foo.hello[0]", "bar[1].couch").execute();
assertTrue(ds.next());
assertEquals("Row[values=[world, db]]", ds.getRow().toString());
assertFalse(ds.next());
ds.close();
} finally {
dc.executeUpdate(new DropTable(table));
}
}
示例9: getColumnTypeFromMetaDataField
private static ColumnType getColumnTypeFromMetaDataField(DataType.Name metaDataName) {
switch (metaDataName) {
case BIGINT:
case COUNTER:
return ColumnType.BIGINT;
case BLOB:
return ColumnType.BLOB;
case BOOLEAN:
return ColumnType.BOOLEAN;
case DECIMAL:
return ColumnType.DECIMAL;
case DOUBLE:
return ColumnType.DOUBLE;
case FLOAT:
return ColumnType.FLOAT;
case INT:
return ColumnType.INTEGER;
case TEXT:
return ColumnType.STRING;
case TIMESTAMP:
return ColumnType.TIMESTAMP;
case UUID:
return ColumnType.UUID;
case VARCHAR:
return ColumnType.VARCHAR;
case VARINT:
return ColumnType.BIGINT;
case LIST:
return ColumnType.LIST;
case MAP:
return ColumnType.MAP;
case CUSTOM:
return ColumnType.OTHER;
case INET:
return ColumnType.INET;
case SET:
return ColumnType.SET;
default:
return ColumnType.STRING;
}
}