Skip to content

Commit

Permalink
WIP first test case for inner join
Browse files Browse the repository at this point in the history
  • Loading branch information
stempler committed Feb 7, 2024
1 parent 2ed2fec commit 8a831f1
Show file tree
Hide file tree
Showing 11 changed files with 283 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ Import-Package: de.fhg.igd.osgi.util,
eu.esdihumboldt.hale.common.core.io.report.impl,
eu.esdihumboldt.hale.common.core.io.supplier,
eu.esdihumboldt.hale.common.core.report,
eu.esdihumboldt.hale.common.instance.io,
eu.esdihumboldt.hale.common.instance.io.impl,
eu.esdihumboldt.hale.common.instance.model,
eu.esdihumboldt.hale.common.schema.io,
eu.esdihumboldt.hale.common.schema.io.impl,
eu.esdihumboldt.hale.common.schema.model,
eu.esdihumboldt.hale.common.schema.model.impl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,17 @@
import eu.esdihumboldt.hale.common.align.io.impl.CastorAlignmentIO;
import eu.esdihumboldt.hale.common.align.io.impl.JaxbAlignmentIO;
import eu.esdihumboldt.hale.common.align.model.Alignment;
import eu.esdihumboldt.hale.common.core.io.HaleIO;
import eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException;
import eu.esdihumboldt.hale.common.core.io.PathUpdate;
import eu.esdihumboldt.hale.common.core.io.report.IOReport;
import eu.esdihumboldt.hale.common.core.io.report.IOReporter;
import eu.esdihumboldt.hale.common.core.io.report.impl.DefaultIOReporter;
import eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier;
import eu.esdihumboldt.hale.common.core.io.supplier.Locatable;
import eu.esdihumboldt.hale.common.instance.io.InstanceReader;
import eu.esdihumboldt.hale.common.instance.model.InstanceCollection;
import eu.esdihumboldt.hale.common.schema.io.SchemaReader;
import eu.esdihumboldt.hale.common.schema.model.Schema;
import eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeIndex;
import eu.esdihumboldt.hale.io.gml.reader.internal.XmlInstanceReader;
Expand All @@ -59,7 +62,7 @@
public class TestUtil {

/**
* Loads the specified XML Schema.
* Loads the specified schema.
*
* @param location the URI specifying the location of the schema
* @return the loaded schema
Expand All @@ -71,7 +74,11 @@ public static Schema loadSchema(URI location)
throws IOProviderConfigurationException, IOException {
DefaultInputSupplier input = new DefaultInputSupplier(location);

XmlSchemaReader reader = new XmlSchemaReader();
SchemaReader reader = HaleIO.findIOProvider(SchemaReader.class, input, location.getPath());
if (reader == null) {
// assume XML schema as default
reader = new XmlSchemaReader();
}
reader.setSharedTypes(new DefaultTypeIndex());
reader.setSource(input);

Expand Down Expand Up @@ -120,10 +127,10 @@ public URI getLocation() {
}

/**
* Loads an instance collection from the specified XML file with the given
* Loads an instance collection from the specified file with the given
* source types.
*
* @param location the URI specifying the location of the xml instance file
* @param location the URI specifying the location of the instance file
* @param types the type index
* @return the loaded instance collection
* @throws IOException if loading the instance failed
Expand All @@ -134,7 +141,12 @@ public static InstanceCollection loadInstances(URI location, Schema types)
throws IOProviderConfigurationException, IOException {
DefaultInputSupplier input = new DefaultInputSupplier(location);

XmlInstanceReader instanceReader = new XmlInstanceReader();
InstanceReader instanceReader = HaleIO.findIOProvider(InstanceReader.class, input,
location.getPath());
if (instanceReader == null) {
// assume XML as default
instanceReader = new XmlInstanceReader();
}
instanceReader.setSource(input);
instanceReader.setSourceSchema(types);
IOReport report = instanceReader.execute(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,16 @@ public void testPropertyJoinIntFloat() throws Exception {
TransformationExamples.getExample(TransformationExamples.PROPERTY_JOIN_INT_FLOAT));
}

/**
* Test a Join that has the innerJoin flag enabled.
*
* @throws Exception if an error occurs executing the test
*/
@Test
public void testInnerJoin() throws Exception {
testTransform(TransformationExamples.getExample(TransformationExamples.INNER_JOIN));
}

@Override
protected List<Instance> transformData(TransformationExample example) throws Exception {
ConceptualSchemaTransformer transformer = new ConceptualSchemaTransformer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ abstract class TransformationExamples {

public static final String XSL_XPATH_1 = 'xpath1'

public static final String INNER_JOIN = 'inner_join'

/**
* Internal example map.
*/
Expand Down Expand Up @@ -225,7 +227,10 @@ abstract class TransformationExamples {
(CM_NESTED_6): defaultExample(CM_NESTED_6),

// XSL only examples
(XSL_XPATH_1): defaultExample(XSL_XPATH_1)
(XSL_XPATH_1): defaultExample(XSL_XPATH_1),

// builder based examples
(INNER_JOIN): builderExample(INNER_JOIN)
];

static def defaultExample(String folder) {
Expand All @@ -240,6 +245,19 @@ abstract class TransformationExamples {
]
}

static def builderExample(String folder) {
[
sourceSchema: "/testdata/${folder}/source-schema.groovy",
targetSchema: "/testdata/${folder}/target-schema.groovy",
alignment: "/testdata/${folder}/mapping.halex.alignment.xml",
sourceData: "/testdata/${folder}/source-instances.groovy",
transformedData: "/testdata/${folder}/target-instances.groovy",
// not relevant:
containerNamespace: null,
containerName: null
]
}

/**
* Get the transformation example with the given identifier.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<hale-project version="5.1.0.qualifier">
<name>mapping</name>
<author>hale</author>
<created>2024-02-07T10:28:58.718+01:00</created>
<modified>2024-02-07T10:39:07.594+01:00</modified>
<save-config action-id="project.save" provider-id="eu.esdihumboldt.hale.io.project.hale25.xml.writer">
<setting name="charset">UTF-8</setting>
<setting name="projectFiles.separate">false</setting>
<setting name="contentType">eu.esdihumboldt.hale.io.project.hale25.xml</setting>
<setting name="target">file:/home/simon/repos/hale/cst/plugins/eu.esdihumboldt.cst.test/testdata/inner_join/mapping.halex</setting>
</save-config>
<resource action-id="eu.esdihumboldt.hale.io.schema.read.source" provider-id="eu.esdihumboldt.hale.io.schemabuilder">
<setting name="charset">UTF-8</setting>
<setting name="resourceId">ec2ec25e-5940-4b91-8ccd-9ea9455a3dbc</setting>
<setting name="source">source-schema.groovy</setting>
<setting name="contentType">eu.esdihumboldt.hale.io.schemabuilder</setting>
</resource>
<resource action-id="eu.esdihumboldt.hale.io.schema.read.target" provider-id="eu.esdihumboldt.hale.io.schemabuilder">
<setting name="charset">UTF-8</setting>
<setting name="resourceId">646e49d6-a2f9-462c-8bfb-e6a2a47abef1</setting>
<setting name="source">target-schema.groovy</setting>
<setting name="contentType">eu.esdihumboldt.hale.io.schemabuilder</setting>
</resource>
<resource action-id="eu.esdihumboldt.hale.io.instance.read.source" provider-id="eu.esdihumboldt.hale.io.instancebuilder">
<setting name="charset">UTF-8</setting>
<setting name="resourceId">95bd5843-dfc0-43be-a901-03e7b843d44a</setting>
<setting name="source">source-instances.groovy</setting>
<setting name="contentType">eu.esdihumboldt.hale.io.instancebuilder</setting>
</resource>
<file name="alignment.xml" location="mapping.halex.alignment.xml"/>
<file name="styles.sld" location="mapping.halex.styles.sld"/>
</hale-project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<alignment xmlns="http://www.esdi-humboldt.eu/hale/alignment">
<cell relation="eu.esdihumboldt.hale.align.join" id="Ccb953cb3-15d3-44c5-bea4-685b6e217b1f" priority="normal">
<source name="types">
<class>
<type name="A" ns="source"/>
</class>
</source>
<source name="types">
<class>
<type name="B" ns="source"/>
</class>
</source>
<source name="types">
<class>
<type name="C" ns="source"/>
</class>
</source>
<target>
<class>
<type name="T" ns="target"/>
</class>
</target>
<parameter value="true" name="innerJoin"/>
<complexParameter name="join">
<jp:join-parameter xmlns:jp="http://www.esdi-humboldt.eu/hale/join">
<class>
<type name="A" ns="source"/>
</class>
<class>
<type name="B" ns="source"/>
</class>
<class>
<type name="C" ns="source"/>
</class>
<jp:condition>
<property>
<type name="A" ns="source"/>
<child name="a" ns="source"/>
</property>
<property>
<type name="B" ns="source"/>
<child name="a" ns="source"/>
</property>
</jp:condition>
<jp:condition>
<property>
<type name="B" ns="source"/>
<child name="b" ns="source"/>
</property>
<property>
<type name="C" ns="source"/>
<child name="b" ns="source"/>
</property>
</jp:condition>
</jp:join-parameter>
</complexParameter>
</cell>
<cell relation="eu.esdihumboldt.hale.align.rename" id="C6a559ff9-954f-4372-b502-fddb4af76b98" priority="normal">
<source>
<property>
<type name="A" ns="source"/>
<child name="a" ns="source"/>
</property>
</source>
<target>
<property>
<type name="T" ns="target"/>
<child name="a" ns="target"/>
</property>
</target>
<parameter value="false" name="ignoreNamespaces"/>
<parameter value="false" name="structuralRename"/>
</cell>
<cell relation="eu.esdihumboldt.hale.align.rename" id="C4bd7cbc7-ea96-4c2d-a46b-711d52746815" priority="normal">
<source>
<property>
<type name="B" ns="source"/>
<child name="b" ns="source"/>
</property>
</source>
<target>
<property>
<type name="T" ns="target"/>
<child name="b" ns="target"/>
</property>
</target>
<parameter value="false" name="ignoreNamespaces"/>
<parameter value="false" name="structuralRename"/>
</cell>
<cell relation="eu.esdihumboldt.hale.align.rename" id="Cf500df0d-5694-4646-8b2f-9b15348ad719" priority="normal">
<source>
<property>
<type name="C" ns="source"/>
<child name="c" ns="source"/>
</property>
</source>
<target>
<property>
<type name="T" ns="target"/>
<child name="c" ns="target"/>
</property>
</target>
<parameter value="false" name="ignoreNamespaces"/>
<parameter value="false" name="structuralRename"/>
</cell>
</alignment>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?><sld:UserStyle xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc">
<sld:Name>Default Styler</sld:Name>
</sld:UserStyle>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
createCollection {

/*
* Sets of instances that are joined
*/

A {
a('a1')
}
B {
a('a1')
b('b1')
}
C {
b('b1')
c('c1')
}

A {
a('a3')
}
B {
a('a3')
b('b1')
}

/*
* Sets of instances that are not joined because of missing links
*/

A {
a('a2')
}
B {
a('a2')
b('b2')
}
C {
b('c2')
c('c2')
}

A {
a('a4')
}
B {
a('a4')
b('b4')
}

A {
a('a5')
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
schema('source') {
A {
a()
}

B {
a()
b(cardinality: '?')
}

C {
b()
c(cardinality: '?')
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
createCollection {

T {
a('a1')
b('b1')
c('c1')
}

T {
a('a3')
b('b1')
c('c1')
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
schema('target') {
T {
a()
b()
c()
}
}

0 comments on commit 8a831f1

Please sign in to comment.