当前位置: 首页>>代码示例>>Java>>正文


Java StructType类代码示例

本文整理汇总了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);
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:16,代码来源:DrillMetaImpl.java

示例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]);
  }
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:52,代码来源:StructImplTest.java


注:本文中的org.apache.calcite.avatica.ColumnMetaData.StructType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。