Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions model/engine/model/engine.ecore
Original file line number Diff line number Diff line change
Expand Up @@ -12033,9 +12033,6 @@
<details key="name" value="Event"/>
<details key="namespace" value="##targetNamespace"/>
</eAnnotations>
<eAnnotations source="https://www.daanse.org/spec/xmla/1.0">
<details key="wrapperElementName" value="Events"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EReference" name="xEvent" eType="ecore:EClass http://schemas.microsoft.com/analysisservices/2011/engine/300/300#//XEvent"
containment="true" resolveProxies="false">
Expand Down
27 changes: 27 additions & 0 deletions model/io/LOCAL-ROWSET-ANSWERS.md
Original file line number Diff line number Diff line change
@@ -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` |
| `<REQUEST_TYPE>.xsd` | the inline schema of the answer to that request type: columns and types, no rows | `EveryRowsetOfAnalysisServicesIsInTheModelTest` |

## How such files are made

- `<REQUEST_TYPE>.xsd` is the `xsd:schema` element of a Discover answer, written as a document of its own.
- `<REQUEST_TYPE>.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.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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 <Create xmlns=".../2003/engine"><ObjectDefinition><Trace>}); {@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 <Execute>} element: the command, then the properties. */
public static void write(XMLStreamWriter out, Command command, PropertyList properties) throws XMLStreamException {
out.setDefaultNamespace(XmlaNamespaces.XMLA);
Expand All @@ -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 - <Statement>, <Alter> - 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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <MEMBER_VALUE xsi:type="xsd:dateTime">2024-03-01T00:00:00</MEMBER_VALUE>}. 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("<MEMBER_VALUE xsi:type=\"xsd:dateTime\">2024-03-01T00:00:00</MEMBER_VALUE>");
}
}
Original file line number Diff line number Diff line change
@@ -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 <Trace><Events><Event>}. 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<Element> children(Element parent) {
List<Element> 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<Element> 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");
}
}
Original file line number Diff line number Diff line change
@@ -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<String, String> 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> 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<Listed> 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());
}
}
}
Loading
Loading