Search in sources :

Example 1 with TypeInfo

use of org.hl7.elm_modelinfo.r1.TypeInfo in project quality-measure-and-cohort-service by Alvearie.

the class ModelUtilsTest method testGetBaseTypeNameIncludedNamespacePrefixMissing.

@Test
public void testGetBaseTypeNameIncludedNamespacePrefixMissing() {
    ModelSpecifier otherModel = new ModelSpecifier().withName("Other").withVersion("1.2.3").withUrl("urn:oid:Other");
    ModelInfo modelInfo = new ModelInfo();
    modelInfo.setName("Dummy");
    modelInfo.setVersion("5.4.3");
    modelInfo.setUrl("urn:oid:Dummy");
    modelInfo.getRequiredModelInfo().add(otherModel);
    ClassInfo typeInfo = new ClassInfo();
    typeInfo.setName("MyType");
    typeInfo.setBaseType("Missing.BaseType");
    IllegalArgumentException iex = assertThrows(IllegalArgumentException.class, () -> ModelUtils.getBaseTypeName(modelInfo, typeInfo));
    assertTrue(iex.getMessage(), iex.getMessage().contains("Missing"));
    assertTrue(iex.getMessage(), iex.getMessage().contains(modelInfo.getName()));
    assertTrue(iex.getMessage(), iex.getMessage().contains(modelInfo.getVersion()));
}
Also used : ModelInfo(org.hl7.elm_modelinfo.r1.ModelInfo) ModelSpecifier(org.hl7.elm_modelinfo.r1.ModelSpecifier) ClassInfo(org.hl7.elm_modelinfo.r1.ClassInfo) Test(org.junit.Test)

Example 2 with TypeInfo

use of org.hl7.elm_modelinfo.r1.TypeInfo in project quality-measure-and-cohort-service by Alvearie.

the class ModelUtilsTest method testGetBaseTypeNameNoNamespacePrefix.

@Test
public void testGetBaseTypeNameNoNamespacePrefix() {
    ModelInfo modelInfo = new ModelInfo();
    modelInfo.setName("Dummy");
    modelInfo.setUrl("urn:oid:Dummy");
    ClassInfo typeInfo = new ClassInfo();
    typeInfo.setName("MyType");
    typeInfo.setBaseType("BaseType");
    QName qname = ModelUtils.getBaseTypeName(modelInfo, typeInfo);
    assertEquals(new QName(modelInfo.getUrl(), "BaseType"), qname);
}
Also used : ModelInfo(org.hl7.elm_modelinfo.r1.ModelInfo) QName(javax.xml.namespace.QName) ClassInfo(org.hl7.elm_modelinfo.r1.ClassInfo) Test(org.junit.Test)

Example 3 with TypeInfo

use of org.hl7.elm_modelinfo.r1.TypeInfo in project quality-measure-and-cohort-service by Alvearie.

the class ModelUtilsTest method testGetBaseTypeNameSystemNamespacePrefix.

@Test
public void testGetBaseTypeNameSystemNamespacePrefix() {
    ModelInfo modelInfo = new ModelInfo();
    modelInfo.setName("Dummy");
    modelInfo.setUrl("urn:oid:Dummy");
    ClassInfo typeInfo = new ClassInfo();
    typeInfo.setName("MyType");
    typeInfo.setBaseType("System.BaseType");
    QName qname = ModelUtils.getBaseTypeName(modelInfo, typeInfo);
    assertEquals(new QName(CqlConstants.SYSTEM_MODEL_URI, "BaseType"), qname);
}
Also used : ModelInfo(org.hl7.elm_modelinfo.r1.ModelInfo) QName(javax.xml.namespace.QName) ClassInfo(org.hl7.elm_modelinfo.r1.ClassInfo) Test(org.junit.Test)

Example 4 with TypeInfo

use of org.hl7.elm_modelinfo.r1.TypeInfo in project coral by linkedin.

the class TypeConverter method convert.

// Mimic the StructTypeInfo conversion to convert a UnionTypeInfo to the corresponding RelDataType
// The schema of output Struct conforms to https://github.com/trinodb/trino/pull/3483
// except we adopted "integer" for the type of "tag" field instead of "tinyint" in the Trino patch
// for compatibility with other platforms that Iceberg currently doesn't support tinyint type.
// Note: this is subject to change in the future pending on the discussion in
// https://mail-archives.apache.org/mod_mbox/iceberg-dev/202112.mbox/browser
public static RelDataType convert(UnionTypeInfo unionType, RelDataTypeFactory dtFactory) {
    List<RelDataType> fTypes = unionType.getAllUnionObjectTypeInfos().stream().map(typeInfo -> convert(typeInfo, dtFactory)).collect(Collectors.toList());
    List<String> fNames = IntStream.range(0, unionType.getAllUnionObjectTypeInfos().size()).mapToObj(i -> "field" + i).collect(Collectors.toList());
    fTypes.add(0, dtFactory.createSqlType(SqlTypeName.INTEGER));
    fNames.add(0, "tag");
    RelDataType rowType = dtFactory.createStructType(fTypes, fNames);
    return dtFactory.createTypeWithNullability(rowType, true);
}
Also used : IntStream(java.util.stream.IntStream) RelDataType(org.apache.calcite.rel.type.RelDataType) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) HiveChar(org.apache.hadoop.hive.common.type.HiveChar) List(java.util.List) SqlTypeName(org.apache.calcite.sql.type.SqlTypeName) org.apache.hadoop.hive.serde.serdeConstants(org.apache.hadoop.hive.serde.serdeConstants) org.apache.hadoop.hive.serde2.typeinfo(org.apache.hadoop.hive.serde2.typeinfo) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) RelDataType(org.apache.calcite.rel.type.RelDataType)

Example 5 with TypeInfo

use of org.hl7.elm_modelinfo.r1.TypeInfo in project quality-measure-and-cohort-service by Alvearie.

the class ModelUtilsTest method testGetChoiceTypesValid.

@Test
public void testGetChoiceTypesValid() {
    ModelInfo modelInfo = JAXB.unmarshal(new File("src/test/resources/abstract-context/modelinfo/abstract-modelinfo-1.0.0.xml"), ModelInfo.class);
    TypeInfo typeInfo = modelInfo.getTypeInfo().stream().map(ClassInfo.class::cast).filter(classInfo -> classInfo.getName().equals("AlphaNumeric")).findFirst().orElse(null);
    Collection<String> choiceTypes = ModelUtils.getChoiceTypeNames(typeInfo);
    assertThat(choiceTypes, Matchers.containsInAnyOrder("Alpha", "Numeric"));
}
Also used : ModelInfo(org.hl7.elm_modelinfo.r1.ModelInfo) File(java.io.File) TypeInfo(org.hl7.elm_modelinfo.r1.TypeInfo) Test(org.junit.Test)

Aggregations

ModelInfo (org.hl7.elm_modelinfo.r1.ModelInfo)9 Test (org.junit.Test)9 ClassInfo (org.hl7.elm_modelinfo.r1.ClassInfo)8 QName (javax.xml.namespace.QName)4 TypeInfo (org.hl7.elm_modelinfo.r1.TypeInfo)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 ModelSpecifier (org.hl7.elm_modelinfo.r1.ModelSpecifier)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)1 SqlTypeName (org.apache.calcite.sql.type.SqlTypeName)1 HiveChar (org.apache.hadoop.hive.common.type.HiveChar)1 org.apache.hadoop.hive.serde.serdeConstants (org.apache.hadoop.hive.serde.serdeConstants)1 org.apache.hadoop.hive.serde2.typeinfo (org.apache.hadoop.hive.serde2.typeinfo)1 ChoiceTypeSpecifier (org.hl7.elm_modelinfo.r1.ChoiceTypeSpecifier)1 NamedTypeSpecifier (org.hl7.elm_modelinfo.r1.NamedTypeSpecifier)1