Skip to content

Commit

Permalink
TEIID-3441 allowing varbinary for xmlparse
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Apr 17, 2015
1 parent 7fcca20 commit 3b836af
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
8 changes: 8 additions & 0 deletions engine/src/main/java/org/teiid/query/eval/Evaluator.java
Expand Up @@ -806,6 +806,14 @@ private Object evaluateXMLParse(List<?> tuple, final XMLParse xp) throws Express
Reader r = new StringReader(string);
type = validate(xp, r);
}
} else if (value instanceof BinaryType) {
BinaryType string = (BinaryType)value;
result = new SQLXMLImpl(string.getBytesDirect());
result.setCharset(Streamable.CHARSET);
if (!xp.isWellFormed()) {
Reader r = result.getCharacterStream();
type = validate(xp, r);
}
} else {
InputStreamFactory isf = null;
Streamable<?> s = (Streamable<?>)value;
Expand Down
Expand Up @@ -1484,7 +1484,8 @@ private void validateTextOptions(LanguageObject obj, Character delimiter,
public void visit(XMLParse obj) {
if (obj.getExpression().getType() != DataTypeManager.DefaultDataClasses.STRING &&
obj.getExpression().getType() != DataTypeManager.DefaultDataClasses.CLOB &&
obj.getExpression().getType() != DataTypeManager.DefaultDataClasses.BLOB) {
obj.getExpression().getType() != DataTypeManager.DefaultDataClasses.BLOB &&
obj.getExpression().getType() != DataTypeManager.DefaultDataClasses.VARBINARY) {
handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.xmlparse_type"), obj); //$NON-NLS-1$
}
}
Expand Down
2 changes: 1 addition & 1 deletion engine/src/main/resources/org/teiid/query/i18n.properties
Expand Up @@ -861,7 +861,7 @@ ValidationVisitor.ValidationVisitor.context_item_not_allowed=OBJECTTABLE does no
ValidationVisitor.one_ordinal=Only one FOR ORDINALITY column is allowed for an XMLTABLE.
ValidationVisitor.invalid_default=XMLTABLE or OBJECTTABLE DEFAULT expression is invalid: "{0}"
ValidationVisitor.context_required=The XQuery requires a context item, but none exists in the PASSING clause.
ValidationVisitor.xmlparse_type=XMLPARSE expects a STRING, CLOB, or BLOB value.
ValidationVisitor.xmlparse_type=XMLPARSE expects a STRING, CLOB, VARBINARY, or BLOB value.
ValidationVisitor.invalid_encoding=Encoding {0} is not valid.
ValidationVisitor.subquery_insert=SELECT INTO should not be used in a subquery.
ValidationVisitor.xmlcast_types=XMLCAST can only be used to cast to and from XML types {0}
Expand Down
Expand Up @@ -52,6 +52,7 @@
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.types.InputStreamFactory;
import org.teiid.core.util.ObjectConverterUtil;
import org.teiid.core.util.PropertiesUtils;
import org.teiid.core.util.TimestampWithTimezone;
import org.teiid.core.util.UnitTestUtil;
import org.teiid.metadata.MetadataStore;
Expand Down Expand Up @@ -312,6 +313,16 @@ public class TestSQLXMLProcessing {
process(sql, expected);
}

@Test public void testXmlTableBOM() throws Exception {
String sql = "select * from xmltable('/a' passing xmlparse(document X'EFBBBF" + PropertiesUtils.toHex("<a/>".getBytes("UTF-8")) + "' wellformed)) as x"; //$NON-NLS-1$

List<?>[] expected = new List<?>[] {
Arrays.asList("<a/>"),
};

process(sql, expected);
}

@Test public void testXsiNil() throws Exception {
String sql = "select * from xmltable('/a/b' passing convert('<a xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><b xsi:nil=\"true\" xsi:type=\"xs:int\"/><b>1</b></a>', xml) columns val integer path '.') as x"; //$NON-NLS-1$

Expand Down Expand Up @@ -653,6 +664,16 @@ public void run() {
process(sql, expected);
}

@Test public void testXmlParseBOM() throws Exception {
String sql = "select xmlparse(content X'EFBBBF" + PropertiesUtils.toHex("<a/>".getBytes("UTF-8")) + "')"; //$NON-NLS-1$

List<?>[] expected = new List<?>[] {
Arrays.asList("<a/>")
};

process(sql, expected);
}

@Test(expected=ExpressionEvaluationException.class) public void testXmlParseContentException() throws Exception {
String sql = "select xmlparse(content 'a<')"; //$NON-NLS-1$

Expand Down

0 comments on commit 3b836af

Please sign in to comment.