diff --git a/model/engine/model/engine.ecore b/model/engine/model/engine.ecore index 7e77792..50657dc 100644 --- a/model/engine/model/engine.ecore +++ b/model/engine/model/engine.ecore @@ -12033,9 +12033,6 @@
- -
- diff --git a/model/io/LOCAL-ROWSET-ANSWERS.md b/model/io/LOCAL-ROWSET-ANSWERS.md new file mode 100644 index 0000000..0efa88b --- /dev/null +++ b/model/io/LOCAL-ROWSET-ANSWERS.md @@ -0,0 +1,27 @@ +# Rowset answers outside the repository + +Two test classes of this module compare the model with the answers Analysis Services 2017 gives to Discover +requests. The answers are not part of this repository. Without them the tests are skipped, and the build runs. + +## Where the tests look + +The system property `xmla.rowset.answers` names the folder; without it the tests read `../../../xmla-rowset-answers`, +a folder beside the repository's working tree. + +```sh +mvn -pl model/io test -Dxmla.rowset.answers=/path/to/the/folder +``` + +## Files + +| File | Holds | Read by | +| --- | --- | --- | +| `DISCOVER_SCHEMA_ROWSETS.rows.xml` | for each rowset its name, GUID, restrictions and restrictions mask | `EveryRowsetOfAnalysisServicesIsInTheModelTest` | +| `DISCOVER_PROPERTIES.rows.xml` | for each request property its name, type, access and whether it is required | `EveryPropertyOfAnalysisServicesIsInTheModelTest` | +| `.xsd` | the inline schema of the answer to that request type: columns and types, no rows | `EveryRowsetOfAnalysisServicesIsInTheModelTest` | + +## How such files are made + +- `.xsd` is the `xsd:schema` element of a Discover answer, written as a document of its own. +- `.rows.xml` is a `root` element in the namespace `urn:schemas-microsoft-com:xml-analysis:rowset` + holding the answer's `row` elements with the columns the tests read. diff --git a/model/io/src/main/java/org/eclipse/daanse/xmla/model/io/ExecuteRequestWriter.java b/model/io/src/main/java/org/eclipse/daanse/xmla/model/io/ExecuteRequestWriter.java index dab0a40..0610f07 100644 --- a/model/io/src/main/java/org/eclipse/daanse/xmla/model/io/ExecuteRequestWriter.java +++ b/model/io/src/main/java/org/eclipse/daanse/xmla/model/io/ExecuteRequestWriter.java @@ -18,6 +18,7 @@ import org.eclipse.daanse.xmla.model.xmla.Command; import org.eclipse.daanse.xmla.model.xmla.PropertyList; +import org.eclipse.emf.ecore.EAnnotation; import org.eclipse.emf.ecore.util.ExtendedMetaData; /** @@ -35,6 +36,21 @@ private ExecuteRequestWriter() { // static access only } + /** + * The namespace a command is written in, as the model states it: every ASSL command carries + * {@code elementNamespace} = the engine namespace in its Daanse annotation, and is written there with everything + * under it ({@code }); {@code Statement} carries none and + * stays in XMLA. The model puts all commands in one package, so the namespace has to be said per command, and saying + * it in the model lets every writer of the model -- this one and the TypeScript client's -- read it from the same + * place. Analysis Services 2017 refuses an ASSL command in the XMLA namespace: "The Create element ... (namespace + * urn:schemas-microsoft-com:xml-analysis) cannot appear under Envelope/Body/Execute/Command". + */ + static String namespaceOf(Command command) { + EAnnotation daanse = command.eClass().getEAnnotation(EcoreXmlWriter.DAANSE_XMLA); + String stated = daanse == null ? null : daanse.getDetails().get("elementNamespace"); + return stated == null ? XmlaNamespaces.XMLA : stated; + } + /** Writes the {@code } element: the command, then the properties. */ public static void write(XMLStreamWriter out, Command command, PropertyList properties) throws XMLStreamException { out.setDefaultNamespace(XmlaNamespaces.XMLA); @@ -45,7 +61,7 @@ public static void write(XMLStreamWriter out, Command command, PropertyList prop if (command != null) { // The element is the command's own name - , - not the // feature's, which is what a server dispatches on. - new EcoreXmlWriter(XmlaNamespaces.XMLA).write(out, command, + new EcoreXmlWriter(namespaceOf(command)).write(out, command, ExtendedMetaData.INSTANCE.getName(command.eClass())); } out.writeEndElement(); diff --git a/model/io/src/test/java/org/eclipse/daanse/xmla/model/io/AMemberPropertyNamesItsTypeAsXsiTypeTest.java b/model/io/src/test/java/org/eclipse/daanse/xmla/model/io/AMemberPropertyNamesItsTypeAsXsiTypeTest.java new file mode 100644 index 0000000..7509399 --- /dev/null +++ b/model/io/src/test/java/org/eclipse/daanse/xmla/model/io/AMemberPropertyNamesItsTypeAsXsiTypeTest.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2026 Contributors to the Eclipse Foundation. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Stefan Bischof (bipolis.org) - initial + */ +package org.eclipse.daanse.xmla.model.io; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.StringWriter; + +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamWriter; + +import org.eclipse.daanse.xmla.model.mddataset.CellProperty; +import org.eclipse.daanse.xmla.model.mddataset.MdDatasetFactory; +import org.eclipse.daanse.xmla.model.mddataset.MemberType; +import org.junit.jupiter.api.Test; + +/** + * A typed member property on an axis names its type as {@code xsi:type}, as Analysis Services writes MEMBER_VALUE of + * a date: {@code 2024-03-01T00:00:00}. Written as a plain + * {@code type} attribute, a client read the value as text. + */ +class AMemberPropertyNamesItsTypeAsXsiTypeTest { + + @Test + void theTypeOfAMemberValueIsAnXsiType() throws Exception { + MdDatasetFactory factory = MdDatasetFactory.eINSTANCE; + MemberType member = factory.createMemberType(); + member.setHierarchy("[Date].[Date]"); + CellProperty value = factory.createCellProperty(); + value.setTagName("MEMBER_VALUE"); + value.setValue("2024-03-01T00:00:00"); + value.setType("xsd:dateTime"); + member.getAny().add(value); + + StringWriter text = new StringWriter(); + XMLStreamWriter out = XMLOutputFactory.newInstance().createXMLStreamWriter(text); + out.setDefaultNamespace(XmlaNamespaces.MDDATASET); + out.writeStartElement(XmlaNamespaces.MDDATASET, "root"); + out.writeDefaultNamespace(XmlaNamespaces.MDDATASET); + out.writeNamespace(XmlaNamespaces.XSI_PREFIX, XmlaNamespaces.XSI); + new EcoreXmlWriter(XmlaNamespaces.MDDATASET).write(out, member, "Member"); + out.writeEndElement(); + out.close(); + + assertThat(text.toString()).contains("2024-03-01T00:00:00"); + } +} diff --git a/model/io/src/test/java/org/eclipse/daanse/xmla/model/io/AnAsslCommandIsWrittenAsAnalysisServicesReadsItTest.java b/model/io/src/test/java/org/eclipse/daanse/xmla/model/io/AnAsslCommandIsWrittenAsAnalysisServicesReadsItTest.java new file mode 100644 index 0000000..24b4f35 --- /dev/null +++ b/model/io/src/test/java/org/eclipse/daanse/xmla/model/io/AnAsslCommandIsWrittenAsAnalysisServicesReadsItTest.java @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2026 Contributors to the Eclipse Foundation. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * SmartCity Jena - initial + * Stefan Bischof (bipolis.org) - initial + */ +package org.eclipse.daanse.xmla.model.io; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamReader; + +import org.eclipse.daanse.xmla.model.engine.EngineFactory; +import org.eclipse.daanse.xmla.model.engine.Event; +import org.eclipse.daanse.xmla.model.engine.EventColumnID; +import org.eclipse.daanse.xmla.model.engine.EventType; +import org.eclipse.daanse.xmla.model.engine.MajorObject; +import org.eclipse.daanse.xmla.model.engine.Trace; +import org.eclipse.daanse.xmla.model.xmla.Command; +import org.eclipse.daanse.xmla.model.xmla.Create; +import org.eclipse.daanse.xmla.model.xmla.Execute; +import org.eclipse.daanse.xmla.model.xmla.Statement; +import org.eclipse.daanse.xmla.model.xmla.XmlaFactory; +import org.junit.jupiter.api.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +/** + * An ASSL command leaves the client in the shape Analysis Services takes: the command and everything under it in the + * engine namespace, the events of a trace as {@code }. Analysis Services 2017 refused both other + * forms the codec wrote before: a {@code Create} in the XMLA namespace ("The Create element ... cannot appear under + * Envelope/Body/Execute/Command") and, since the element of {@code Trace.eventType} is {@code Events}, a second + * {@code Events} the old wrapper of {@code EventType.events} put inside it. A {@code Statement} stays in the XMLA + * namespace. + */ +class AnAsslCommandIsWrittenAsAnalysisServicesReadsItTest { + + private static final EngineFactory ENGINE = EngineFactory.eINSTANCE; + private static final XmlaFactory XMLA = XmlaFactory.eINSTANCE; + + private static Create createOfATrace() { + Trace trace = ENGINE.createTrace(); + trace.setId("T1"); + trace.setName("T1"); + EventType events = ENGINE.createEventType(); + for (String id : List.of("9", "10")) { + Event event = ENGINE.createEvent(); + event.setEventID(id); + EventColumnID columns = ENGINE.createEventColumnID(); + columns.getColumnID().addAll(List.of("0", "42")); + event.setColumns(columns); + events.getEvents().add(event); + } + trace.setEventType(events); + MajorObject definition = ENGINE.createMajorObject(); + definition.setTrace(trace); + Create create = XMLA.createCreate(); + create.setObjectDefinition(definition); + return create; + } + + private static byte[] written(Command command) throws Exception { + ByteArrayOutputStream target = new ByteArrayOutputStream(); + XmlaMessageCodec.writeExecuteRequest(target, List.of(), command, null); + return target.toByteArray(); + } + + private static Element commandOf(byte[] request) throws Exception { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + Document document = factory.newDocumentBuilder().parse(new ByteArrayInputStream(request)); + Element command = (Element) document.getElementsByTagNameNS(XmlaNamespaces.XMLA, "Command").item(0); + return children(command).get(0); + } + + private static List children(Element parent) { + List children = new ArrayList<>(); + for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) { + if (child instanceof Element element) { + children.add(element); + } + } + return children; + } + + private static Element only(Element parent, String name) { + List named = children(parent).stream().filter(child -> child.getLocalName().equals(name)).toList(); + assertThat(named).as(parent.getLocalName() + "/" + name).hasSize(1); + return named.get(0); + } + + @Test + void aCreateAndItsTraceAreInTheEngineNamespace() throws Exception { + Element create = commandOf(written(createOfATrace())); + + assertThat(create.getLocalName()).isEqualTo("Create"); + assertThat(create.getNamespaceURI()).isEqualTo(XmlaNamespaces.ENGINE); + Element trace = only(only(create, "ObjectDefinition"), "Trace"); + assertThat(trace.getNamespaceURI()).isEqualTo(XmlaNamespaces.ENGINE); + assertThat(only(trace, "ID").getNamespaceURI()).isEqualTo(XmlaNamespaces.ENGINE); + } + + @Test + void theEventsOfATraceAreOneEventsElementOfEvents() throws Exception { + Element events = only(only(only(commandOf(written(createOfATrace())), "ObjectDefinition"), "Trace"), "Events"); + + assertThat(children(events)).extracting(Element::getLocalName).containsExactly("Event", "Event"); + assertThat(only(children(events).get(0), "EventID").getTextContent()).isEqualTo("9"); + } + + @Test + void aStatementStaysInTheXmlaNamespace() throws Exception { + Statement statement = XMLA.createStatement(); + statement.setStatement("SELECT FROM [C]"); + + Element written = commandOf(written(statement)); + + assertThat(written.getLocalName()).isEqualTo("Statement"); + assertThat(written.getNamespaceURI()).isEqualTo(XmlaNamespaces.XMLA); + } + + @Test + void whatIsWrittenIsReadBackWithItsEvents() throws Exception { + XMLStreamReader in = XMLInputFactory.newFactory().createXMLStreamReader( + new ByteArrayInputStream(written(createOfATrace()))); + while (!(in.next() == XMLStreamConstants.START_ELEMENT && in.getLocalName().equals("Execute"))) { + // to the Execute element + } + + Execute read = ExecuteRequestReader.read(in); + + Trace trace = ((Create) read.getCommand()).getObjectDefinition().getTrace(); + assertThat(trace.getEventType().getEvents()).extracting(Event::getEventID).containsExactly("9", "10"); + assertThat(trace.getEventType().getEvents().get(0).getColumns().getColumnID()).containsExactly("0", "42"); + } +} diff --git a/model/io/src/test/java/org/eclipse/daanse/xmla/model/io/EveryPropertyOfAnalysisServicesIsInTheModelTest.java b/model/io/src/test/java/org/eclipse/daanse/xmla/model/io/EveryPropertyOfAnalysisServicesIsInTheModelTest.java new file mode 100644 index 0000000..ad018a4 --- /dev/null +++ b/model/io/src/test/java/org/eclipse/daanse/xmla/model/io/EveryPropertyOfAnalysisServicesIsInTheModelTest.java @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2026 Contributors to the Eclipse Foundation. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Stefan Bischof (bipolis.org) - initial + */ +package org.eclipse.daanse.xmla.model.io; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.InputStream; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Stream; + +import javax.xml.parsers.DocumentBuilderFactory; + +import org.eclipse.daanse.xmla.model.xmla.XmlaPackage; +import org.eclipse.emf.ecore.EAnnotation; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.util.ExtendedMetaData; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +/** + * The request properties can carry every property Analysis Services 2017 lists in {@code DISCOVER_PROPERTIES}, with + * its type and, where the model states one, its access. The rows of that answer (name, type, access and whether a + * property is required, not the values) lie outside this repository, see {@link RowsetAnswers}; without them the tests + * are skipped. + */ +class EveryPropertyOfAnalysisServicesIsInTheModelTest { + + private static final String ROWSET = "urn:schemas-microsoft-com:xml-analysis:rowset"; + private static final String PROPERTY = "https://www.daanse.org/spec/xmla/property/1.0"; + + private static final String ANSWER = "DISCOVER_PROPERTIES.rows.xml"; + + /** The Ecore type each type name of DISCOVER_PROPERTIES is read into. */ + private static final Map TYPES = Map.of("string", "EString", "int", "EIntegerObject", "boolean", + "EBooleanObject", "double", "EDoubleObject", "long", "ELongObject"); + + record Listed(String name, String type, String access) { + + @Override + public String toString() { + return name; + } + } + + private static String text(Element row, String name) { + for (Node child = row.getFirstChild(); child != null; child = child.getNextSibling()) { + if (child instanceof Element element && ROWSET.equals(element.getNamespaceURI()) + && name.equals(element.getLocalName())) { + return element.getTextContent(); + } + } + return null; + } + + static Stream listed() throws Exception { + RowsetAnswers.assumePresent(ANSWER); + try (InputStream in = Files.newInputStream(RowsetAnswers.file(ANSWER))) { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + Element root = factory.newDocumentBuilder().parse(in).getDocumentElement(); + List properties = new ArrayList<>(); + for (Node child = root.getFirstChild(); child != null; child = child.getNextSibling()) { + if (child instanceof Element row) { + properties.add(new Listed(text(row, "PropertyName"), text(row, "PropertyType"), + text(row, "PropertyAccessType"))); + } + } + return properties.stream(); + } + } + + @Test + void analysisServicesLists143Properties() throws Exception { + assertThat(listed()).hasSize(143); + } + + @ParameterizedTest + @MethodSource("listed") + void aPropertyAnalysisServicesListsIsInTheModelWithItsTypeAndAccess(Listed property) { + EStructuralFeature feature = XmlaPackage.eINSTANCE.getPropertyList().getEAllStructuralFeatures().stream() + .filter(f -> property.name().equals(ExtendedMetaData.INSTANCE.getName(f))).findFirst().orElse(null); + assertThat(feature).as(property.name() + " is a property of the model").isNotNull(); + assertThat(feature.getEType().getName()).as(property.name() + " type").isEqualTo(TYPES.get(property.type())); + EAnnotation daanse = feature.getEAnnotation(PROPERTY); + String access = daanse == null ? null : daanse.getDetails().get("access"); + if (access != null) { + assertThat(access).as(property.name() + " access").isEqualTo(property.access()); + } + } +} diff --git a/model/io/src/test/java/org/eclipse/daanse/xmla/model/io/EveryRowsetOfAnalysisServicesIsInTheModelTest.java b/model/io/src/test/java/org/eclipse/daanse/xmla/model/io/EveryRowsetOfAnalysisServicesIsInTheModelTest.java new file mode 100644 index 0000000..0056c37 --- /dev/null +++ b/model/io/src/test/java/org/eclipse/daanse/xmla/model/io/EveryRowsetOfAnalysisServicesIsInTheModelTest.java @@ -0,0 +1,206 @@ +/* + * Copyright (c) 2026 Contributors to the Eclipse Foundation. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * SmartCity Jena - initial + * Stefan Bischof (bipolis.org) - initial + */ +package org.eclipse.daanse.xmla.model.io; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.Optional; +import java.util.stream.Stream; + +import javax.xml.parsers.DocumentBuilderFactory; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.util.ExtendedMetaData; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +/** + * The model can carry every rowset Analysis Services 2017 offers, in the form it answers with. + *

+ * It is checked against answers of Analysis Services 2017 in multidimensional mode that lie outside this repository, + * see {@link RowsetAnswers}; without them the tests are skipped. They are the {@code DISCOVER_SCHEMA_ROWSETS} rows (77 + * rowsets, with GUID, restrictions and mask) and, for the 71 rowsets that answer with rows or an empty result, the + * inline schema of the answer -- names and types only, no data. A rowset the server refuses in that mode (Power BI, + * tabular) has no schema there and is held to its row in {@code DISCOVER_SCHEMA_ROWSETS}. + *

+ * What is checked is what a reader of the answer depends on: every column of the answer is a feature of the rowset's + * row class, in the same order, nested columns in the nested class, and the type this model writes into its own + * answer schema is the one Analysis Services writes. The model may know more -- columns and restrictions of later + * versions of [MS-SSAS] -- since a client that reads by name is not hurt by them; it may not know less, because a reader + * that fails on an unknown column fails on the whole answer. + */ +class EveryRowsetOfAnalysisServicesIsInTheModelTest { + + private static final String XSD = "http://www.w3.org/2001/XMLSchema"; + private static final String SQL = "urn:schemas-microsoft-com:xml-sql"; + private static final String ROWSET = "urn:schemas-microsoft-com:xml-analysis:rowset"; + + /** A rowset as Analysis Services lists it in DISCOVER_SCHEMA_ROWSETS. */ + record Listed(String name, String guid, List restrictions, String mask) { + + @Override + public String toString() { + return name; + } + } + + /** The answer in the file of that name, or {@code null} when there is no such file. */ + private static Document parsed(String name) throws Exception { + Path file = RowsetAnswers.file(name); + if (!Files.isRegularFile(file)) { + return null; + } + try (InputStream in = Files.newInputStream(file)) { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + return factory.newDocumentBuilder().parse(in); + } + } + + private static List children(Element parent, String namespace, String name) { + List found = new ArrayList<>(); + for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) { + if (child instanceof Element element && namespace.equals(element.getNamespaceURI()) + && name.equals(element.getLocalName())) { + found.add(element); + } + } + return found; + } + + private static String text(Element parent, String name) { + List found = children(parent, ROWSET, name); + return found.isEmpty() ? null : found.get(0).getTextContent(); + } + + static Stream listed() throws Exception { + RowsetAnswers.assumePresent("DISCOVER_SCHEMA_ROWSETS.rows.xml"); + Element root = parsed("DISCOVER_SCHEMA_ROWSETS.rows.xml").getDocumentElement(); + List rowsets = new ArrayList<>(); + for (Element row : children(root, ROWSET, "row")) { + List restrictions = new ArrayList<>(); + for (Element restriction : children(row, ROWSET, "Restrictions")) { + restrictions.add(new String[] { text(restriction, "Name"), text(restriction, "Type") }); + } + rowsets.add(new Listed(text(row, "SchemaName"), text(row, "SchemaGuid"), restrictions, + text(row, "RestrictionsMask"))); + } + return rowsets.stream(); + } + + @Test + void analysisServicesListsSeventySevenRowsets() throws Exception { + assertThat(listed()).hasSize(77); + } + + @ParameterizedTest + @MethodSource("listed") + void aRowsetAnalysisServicesListsIsModelledWithItsGuidAndRestrictions(Listed rowset) { + Optional row = RowsetCatalog.forRequestType(rowset.name()); + assertThat(row).as(rowset.name() + " has a row class").isPresent(); + assertThat(RowsetCatalog.guidOf(row.get()).map(guid -> guid.toUpperCase(Locale.ROOT))) + .as(rowset.name() + " GUID").contains(rowset.guid().toUpperCase(Locale.ROOT)); + + List modelled = RowsetCatalog.restrictionsOf(row.get()); + List names = modelled.stream().map(RowsetCatalog.Restriction::name).toList(); + List listedNames = rowset.restrictions().stream().map(r -> r[0]).toList(); + assertThat(names).as(rowset.name() + " restrictions").containsSubsequence(listedNames); + for (String[] restriction : rowset.restrictions()) { + RowsetCatalog.Restriction match = modelled.get(names.indexOf(restriction[0])); + assertThat(match.type()).as(rowset.name() + " restriction " + restriction[0] + " type") + .isEqualTo(restriction[1]); + } + if (names.equals(listedNames)) { + assertThat(RowsetCatalog.restrictionsMaskOf(row.get()).toString()).as(rowset.name() + " mask") + .isEqualTo(rowset.mask()); + } + } + + static Stream answered() throws Exception { + List withSchema = new ArrayList<>(); + for (Listed rowset : listed().toList()) { + if (parsed(rowset.name() + ".xsd") != null) { + withSchema.add(rowset.name()); + } + } + return withSchema.stream(); + } + + @Test + void seventyOneRowsetsAnsweredWithASchema() throws Exception { + assertThat(answered()).hasSize(71); + } + + @ParameterizedTest + @MethodSource("answered") + void everyColumnOfTheAnswerIsAColumnOfTheModelInItsOrderAndType(String requestType) throws Exception { + Element schema = parsed(requestType + ".xsd").getDocumentElement(); + Element row = children(schema, XSD, "complexType").stream().filter(t -> "row".equals(t.getAttribute("name"))) + .findFirst().orElseThrow(); + EClass rowClass = RowsetCatalog.forRequestType(requestType).orElseThrow(); + + List problems = new ArrayList<>(); + compare(requestType, children(row, XSD, "sequence").get(0), rowClass, problems); + + assertThat(problems).as(requestType).isEmpty(); + } + + /** The columns of one sequence against one class, nested sequences against the class their feature holds. */ + private static void compare(String path, Element sequence, EClass modelled, List problems) { + List features = modelled.getEAllStructuralFeatures(); + List names = features.stream().map(f -> ExtendedMetaData.INSTANCE.getName(f)).toList(); + int last = -1; + for (Element column : children(sequence, XSD, "element")) { + String name = column.hasAttributeNS(SQL, "field") ? column.getAttributeNS(SQL, "field") + : column.getAttribute("name"); + int at = names.indexOf(name); + if (at < 0) { + problems.add(path + "/" + name + " is not in the model"); + continue; + } + if (at < last) { + problems.add(path + "/" + name + " stands before " + names.get(last) + " in the model"); + } + last = Math.max(last, at); + EStructuralFeature feature = features.get(at); + List nested = children(column, XSD, "complexType"); + if (!nested.isEmpty()) { + if (feature instanceof EReference reference) { + compare(path + "/" + name, children(nested.get(0), XSD, "sequence").get(0), + reference.getEReferenceType(), problems); + } else { + problems.add(path + "/" + name + " is nested in the answer, a value in the model"); + } + continue; + } + String answered = column.getAttribute("type"); + String written = RowsetSchemaWriter.xsdTypeOf(feature); + if (!answered.isEmpty() && !answered.equals(written)) { + problems.add(path + "/" + name + " is " + answered + " in the answer, " + written + " in the model"); + } + } + } +} diff --git a/model/io/src/test/java/org/eclipse/daanse/xmla/model/io/RowsetAnswers.java b/model/io/src/test/java/org/eclipse/daanse/xmla/model/io/RowsetAnswers.java new file mode 100644 index 0000000..dbd8a0f --- /dev/null +++ b/model/io/src/test/java/org/eclipse/daanse/xmla/model/io/RowsetAnswers.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2026 Contributors to the Eclipse Foundation. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Stefan Bischof (bipolis.org) - initial + */ +package org.eclipse.daanse.xmla.model.io; + +import java.nio.file.Files; +import java.nio.file.Path; + +import org.junit.jupiter.api.Assumptions; + +/** + * The answers of Analysis Services 2017 that the model is checked against: the rows of {@code DISCOVER_SCHEMA_ROWSETS} + * and {@code DISCOVER_PROPERTIES} and the inline schema of each rowset's answer. They lie in a folder outside this + * repository, named by the system property {@value #PROPERTY}; LOCAL-ROWSET-ANSWERS.md of this module lists the files + * and how to get them. A test that reads them is skipped when its file is not there. + */ +final class RowsetAnswers { + + /** The system property that names the folder. */ + static final String PROPERTY = "xmla.rowset.answers"; + + /** The folder, by default beside this repository's working tree, relative to this module. */ + static final Path FOLDER = Path.of(System.getProperty(PROPERTY, "../../../xmla-rowset-answers")); + + private RowsetAnswers() { + } + + /** The file of that name in the folder, whether it is there or not. */ + static Path file(String name) { + return FOLDER.resolve(name); + } + + /** Aborts the calling test, which then counts as skipped, unless the file of that name is in the folder. */ + static void assumePresent(String name) { + Path file = file(name); + Assumptions.assumeTrue(Files.isRegularFile(file), + () -> "no rowset answers at " + file.toAbsolutePath().normalize() + " (set -D" + PROPERTY + ")"); + } +} diff --git a/model/mddataset/model/mddataset.ecore b/model/mddataset/model/mddataset.ecore index cce0dbf..46783b6 100644 --- a/model/mddataset/model/mddataset.ecore +++ b/model/mddataset/model/mddataset.ecore @@ -890,9 +890,13 @@ + +

+
+
+ + +
+ + +
+
+
+ +
diff --git a/model/rowset.server/model/rowset-server.ecore b/model/rowset.server/model/rowset-server.ecore index 11d9554..6ab6c5d 100644 --- a/model/rowset.server/model/rowset-server.ecore +++ b/model/rowset.server/model/rowset-server.ecore @@ -679,9 +679,9 @@
- + -
+
@@ -1893,23 +1893,23 @@
- + -
+
-
+
- + -
+
-
+
@@ -2419,6 +2419,56 @@
+ + +
+ + +
+
+
+ + + + +
+ + +
+
+
+ + + + +
+ + +
+
+
+ + + + +
+ + +
+
+
+ + + + +
+ + +
+
+
+ +
@@ -2971,9 +3021,9 @@
- + -
+
@@ -3060,6 +3110,16 @@
+ + +
+ + +
+
+
+ +
@@ -3306,6 +3366,16 @@
+ + +
+ + +
+
+
+ +
@@ -4002,9 +4072,9 @@
- + -
+
@@ -5877,4 +5947,139 @@ + + +
+ + +
+
+ + +
+
+ + + +
+
+
+ + + + + +
+ + +
+
+ + +
+
+
+
+
+ + + + +
+ + +
+
+ + +
+
+ + + +
+
+
+ + + + +
+
+
+ + + + +
+
+
+ + + + + +
+ + +
+
+ + +
+
+
+
+
+ + + + +
+ + +
+
+ + +
+
+ + + +
+
+
+ + + + +
+
+
+ + + + + +
+ + +
+
+ + +
+
+
+
+
+ + diff --git a/model/xmla/model/xmla.ecore b/model/xmla/model/xmla.ecore index 64a4938..4bcf208 100644 --- a/model/xmla/model/xmla.ecore +++ b/model/xmla/model/xmla.ecore @@ -421,6 +421,9 @@ + + + @@ -1203,7 +1206,7 @@ -
+
@@ -1362,7 +1365,7 @@ + eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//ELongObject">
@@ -1390,7 +1393,7 @@
- +
@@ -2517,6 +2520,32 @@
+ + +
+ + +
+ + +
+
+
+ + + + +
+ + +
+ + +
+
+
+ + @@ -2547,6 +2576,7 @@
+
@@ -2613,6 +2643,7 @@
+
@@ -2665,6 +2696,7 @@
+
@@ -2736,6 +2768,7 @@
+
@@ -2788,6 +2821,7 @@
+
@@ -2880,6 +2914,7 @@ +
@@ -2974,6 +3009,7 @@ +
@@ -2986,6 +3022,7 @@
+
@@ -3008,6 +3045,7 @@
+
@@ -3061,6 +3099,7 @@
+
@@ -3093,6 +3132,7 @@
+
@@ -3180,6 +3220,7 @@
+
@@ -3213,6 +3254,7 @@
+
@@ -3258,6 +3300,7 @@
+
@@ -3292,6 +3335,7 @@
+
@@ -3335,6 +3379,7 @@
+
@@ -3369,6 +3414,7 @@
+
@@ -3404,6 +3450,7 @@
+
@@ -3492,6 +3539,7 @@
+
@@ -3615,6 +3663,7 @@ +
@@ -3627,6 +3676,7 @@
+
@@ -3660,6 +3710,7 @@
+
@@ -3724,6 +3775,7 @@
+
@@ -3746,6 +3798,7 @@
+
@@ -3811,6 +3864,7 @@
+
@@ -3861,6 +3915,7 @@ +
@@ -3889,6 +3944,7 @@ +
@@ -3912,6 +3968,7 @@ +
@@ -4020,6 +4077,7 @@ +
@@ -4053,6 +4111,7 @@ +
@@ -4086,6 +4145,7 @@ +
@@ -4108,6 +4168,7 @@ +
@@ -5461,6 +5522,7 @@
+