本文整理汇总了Java中org.apache.calcite.avatica.ColumnMetaData.StructType类的典型用法代码示例。如果您正苦于以下问题:Java StructType类的具体用法?Java StructType怎么用?Java StructType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StructType类属于org.apache.calcite.avatica.ColumnMetaData包,在下文中一共展示了StructType类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drillFieldMetaData
import org.apache.calcite.avatica.ColumnMetaData.StructType; //导入依赖的package包/类
protected static ColumnMetaData.StructType drillFieldMetaData(Class<?> clazz) {
final List<ColumnMetaData> list = new ArrayList<>();
for (Field field : clazz.getFields()) {
if (Modifier.isPublic(field.getModifiers())
&& !Modifier.isStatic(field.getModifiers())) {
NotNull notNull = field.getAnnotation(NotNull.class);
boolean notNullable = (notNull != null || field.getType().isPrimitive());
list.add(
drillColumnMetaData(
AvaticaUtils.camelToUpper(field.getName()),
list.size(), field.getType(), notNullable));
}
}
return ColumnMetaData.struct(list);
}
示例2: structAccessor
import org.apache.calcite.avatica.ColumnMetaData.StructType; //导入依赖的package包/类
@Test public void structAccessor() throws Exception {
// Define the struct type we're creating
ColumnMetaData intMetaData = MetaImpl.columnMetaData("MY_INT", 1, int.class, false);
ColumnMetaData stringMetaData = MetaImpl.columnMetaData("MY_STRING", 2, String.class, true);
StructType structType = ColumnMetaData.struct(Arrays.asList(intMetaData, stringMetaData));
// Create some structs
Struct struct1 = new StructImpl(Arrays.<Object>asList(1, "one"));
Struct struct2 = new StructImpl(Arrays.<Object>asList(2, "two"));
Struct struct3 = new StructImpl(Arrays.<Object>asList(3));
Struct struct4 = new StructImpl(Arrays.<Object>asList(4, "four", "ignored"));
ColumnMetaData structMetaData = MetaImpl.columnMetaData("MY_STRUCT", 1, structType, false);
List<List<Object>> rows = Arrays.asList(Collections.<Object>singletonList(struct1),
Collections.<Object>singletonList(struct2), Collections.<Object>singletonList(struct3),
Collections.<Object>singletonList(struct4));
// Create four rows, each with one (struct) column
try (Cursor cursor = new ListIteratorCursor(rows.iterator())) {
List<Accessor> accessors = cursor.createAccessors(Collections.singletonList(structMetaData),
Unsafe.localCalendar(), null);
assertEquals(1, accessors.size());
Accessor accessor = accessors.get(0);
assertTrue(cursor.next());
Struct s = accessor.getObject(Struct.class);
Object[] structData = s.getAttributes();
assertEquals(2, structData.length);
assertEquals(1, structData[0]);
assertEquals("one", structData[1]);
assertTrue(cursor.next());
s = accessor.getObject(Struct.class);
structData = s.getAttributes();
assertEquals(2, structData.length);
assertEquals(2, structData[0]);
assertEquals("two", structData[1]);
assertTrue(cursor.next());
s = accessor.getObject(Struct.class);
structData = s.getAttributes();
assertEquals(1, structData.length);
assertEquals(3, structData[0]);
assertTrue(cursor.next());
s = accessor.getObject(Struct.class);
structData = s.getAttributes();
assertEquals(3, structData.length);
assertEquals(4, structData[0]);
assertEquals("four", structData[1]);
// We didn't provide metadata, but we still expect to see it.
assertEquals("ignored", structData[2]);
}
}