Skip to content

Commit

Permalink
MONDRIAN-613 Better handling of cross platform data types while build…
Browse files Browse the repository at this point in the history
…ing an XMLA drillthrough response.

[git-p4: depot-paths = "//open/mondrian-release/3.2/": change = 13928]
  • Loading branch information
lucboudreau committed Nov 22, 2010
1 parent 5d16ace commit f97892e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
39 changes: 19 additions & 20 deletions src/main/mondrian/xmla/XmlaHandler.java
Expand Up @@ -1404,14 +1404,14 @@ static class Column {
private final String encodedName;
private final String xsdType;

Column(String name, int type) {
Column(String name, int type, int scale) {
this.name = name;

// replace invalid XML element name, like " ", with "_x0020_" in
// column headers, otherwise will generate a badly-formatted xml
// doc.
this.encodedName = XmlaUtil.encodeElementName(name);
this.xsdType = sqlToXsdType(type);
this.xsdType = sqlToXsdType(type, scale);
}
}

Expand Down Expand Up @@ -1444,7 +1444,8 @@ public TabularRowSet(
columns.add(
new Column(
md.getColumnLabel(i + 1),
md.getColumnType(i + 1)));
md.getColumnType(i + 1),
md.getScale(i + 1)));
}

// Populate data; assume that SqlStatement is already positioned
Expand Down Expand Up @@ -1485,7 +1486,8 @@ public TabularRowSet(
columns.add(
new Column(
tableName + "." + fieldName,
Types.VARCHAR)); // don't know the real type
Types.VARCHAR, // don't know the real type
0));
}
}

Expand Down Expand Up @@ -1518,18 +1520,6 @@ public void unparse(SaxWriter writer) throws SAXException {
new Object[] {
"xsi:type",
columns.get(i).xsdType});

// final String xsdType = columns.get(i).xsdType;
// if (xsdType.equals(XSD_STRING)) {
// writer.startElement(columns.get(i).encodedName);
// } else {
// writer.startElement(
// columns.get(i).encodedName,
// new Object[] {"xsi:type", xsdType});
// }

// writer.startElement(columns.get(i).encodedName);

Object value = row[i];
if (value == null) {
writer.characters("null");
Expand Down Expand Up @@ -1620,18 +1610,27 @@ public void metadata(SaxWriter writer) {
* @param sqlType SQL type
* @return XSD type
*/
private static String sqlToXsdType(int sqlType) {
private static String sqlToXsdType(final int sqlType, final int scale) {
switch (sqlType) {
// Integer
case Types.INTEGER:
case Types.SMALLINT:
case Types.TINYINT:
return XSD_INT;
case Types.NUMERIC:
case Types.DECIMAL:
/*
* Oracle reports all numbers as NUMERIC. We check
* the scale of the column and pick the right XSD type.
*/
if (scale == 0) {
return XSD_INT;
} else {
return XSD_DECIMAL;
}
case Types.BIGINT:
return XSD_INTEGER;
case Types.NUMERIC:
return XSD_DECIMAL;
// Real
// Real
case Types.DOUBLE:
case Types.FLOAT:
return XSD_DOUBLE;
Expand Down
8 changes: 4 additions & 4 deletions testsrc/main/mondrian/xmla/XmlaBasicTest.ref.xml
Expand Up @@ -13590,7 +13590,7 @@ xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
<xsd:element minOccurs="0" name="Gender" sql:field="Gender" type="xsd:string"/>
<xsd:element minOccurs="0" name="Marital_x0020_Status" sql:field="Marital Status" type="xsd:string"/>
<xsd:element minOccurs="0" name="Yearly_x0020_Income" sql:field="Yearly Income" type="xsd:string"/>
<xsd:element minOccurs="0" name="Unit_x0020_Sales" sql:field="Unit Sales" type="xsd:string"/>
<xsd:element minOccurs="0" name="Unit_x0020_Sales" sql:field="Unit Sales" type="xsd:decimal"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
Expand Down Expand Up @@ -13652,7 +13652,7 @@ xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
<Gender xsi:type="xsd:string">M</Gender>
<Marital_x0020_Status xsi:type="xsd:string">M</Marital_x0020_Status>
<Yearly_x0020_Income xsi:type="xsd:string">$110K - $130K</Yearly_x0020_Income>
<Unit_x0020_Sales xsi:type="xsd:string">3</Unit_x0020_Sales>
<Unit_x0020_Sales xsi:type="xsd:decimal">3</Unit_x0020_Sales>
</row>
<row>
<Store_x0020_Country xsi:type="xsd:string">USA</Store_x0020_Country>
Expand Down Expand Up @@ -13682,7 +13682,7 @@ xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
<Gender xsi:type="xsd:string">M</Gender>
<Marital_x0020_Status xsi:type="xsd:string">M</Marital_x0020_Status>
<Yearly_x0020_Income xsi:type="xsd:string">$110K - $130K</Yearly_x0020_Income>
<Unit_x0020_Sales xsi:type="xsd:string">3</Unit_x0020_Sales>
<Unit_x0020_Sales xsi:type="xsd:decimal">3</Unit_x0020_Sales>
</row>
<row>
<Store_x0020_Country xsi:type="xsd:string">USA</Store_x0020_Country>
Expand Down Expand Up @@ -13712,7 +13712,7 @@ xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
<Gender xsi:type="xsd:string">M</Gender>
<Marital_x0020_Status xsi:type="xsd:string">M</Marital_x0020_Status>
<Yearly_x0020_Income xsi:type="xsd:string">$110K - $130K</Yearly_x0020_Income>
<Unit_x0020_Sales xsi:type="xsd:string">3</Unit_x0020_Sales>
<Unit_x0020_Sales xsi:type="xsd:decimal">3</Unit_x0020_Sales>
</row>
</root>
</cxmla:return>
Expand Down

0 comments on commit f97892e

Please sign in to comment.