@Test public void testXMLTable() throws Exception { String sql = "SELECT * from xmltable(xmlnamespaces(no default), '/' columns x for ordinality, y date default {d'2000-01-01'} path '@date') as x"; //$NON-NLS-1$ Query query = new Query(); query.setSelect(new Select(Arrays.asList(new MultipleElementSymbol()))); XMLTable xt = new XMLTable(); xt.setName("x"); xt.setNamespaces(new XMLNamespaces(Arrays.asList(new XMLNamespaces.NamespaceItem()))); xt.setXquery("/"); List<XMLTable.XMLColumn> columns = new ArrayList<XMLTable.XMLColumn>(); columns.add(new XMLTable.XMLColumn("x")); columns.add(new XMLTable.XMLColumn("y", "date", "@date", new Constant(Date.valueOf("2000-01-01")))); xt.setColumns(columns); query.setFrom(new From(Arrays.asList(xt))); helpTest(sql, "SELECT * FROM XMLTABLE(XMLNAMESPACES(NO DEFAULT), '/' COLUMNS x FOR ORDINALITY, y date DEFAULT {d'2000-01-01'} PATH '@date') AS x", query); }
@Override protected XMLTable cloneDirect() { XMLTable clone = new XMLTable(); this.copy(clone); for (XMLColumn column : columns) { clone.getColumns().add(column.clone()); } if (this.namespaces != null) { clone.namespaces = this.namespaces.clone(); } if (this.passing != null) { for (DerivedColumn col : this.passing) { clone.passing.add(col.clone()); } } clone.xquery = this.xquery; if (this.xqueryExpression != null) { clone.xqueryExpression = this.xqueryExpression.clone(); } clone.usingDefaultColumn = usingDefaultColumn; return clone; }
List<Object> tuple = new ArrayList<Object>(projectedColumns.size()); for (XMLColumn proColumn : projectedColumns) { if (proColumn.isOrdinal()) { if (rowCount > Integer.MAX_VALUE) { throw new TeiidRuntimeException(new TeiidProcessingException(QueryPlugin.Event.TEIID31174, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31174))); } else { try { XPathExpression path = table.getXQueryExpression().getXPathExpression(proColumn.getName()); XPathDynamicContext dynamicContext = path.createDynamicContext(item); final SequenceIterator pathIter = path.iterate(dynamicContext); Item colItem = pathIter.next(); if (colItem == null) { if (proColumn.getDefaultExpression() != null) { tuple.add(getEvaluator(Collections.emptyMap()).evaluate(proColumn.getDefaultExpression(), null)); } else { tuple.add(null); if (proColumn.getSymbol().getType() == DataTypeManager.DefaultDataClasses.XML) { SequenceIterator pushBack = new PushBackSequenceIterator(pathIter, colItem); XMLType value = table.getXQueryExpression().createXMLType(pushBack, this.getBufferManager(), false, getContext()); if (proColumn.getSymbol().getType().isArray()) { ArrayList<Object> vals = new ArrayList<Object>(); vals.add(getValue(proColumn.getSymbol().getType().getComponentType(), colItem, this.table.getXQueryExpression().getConfig(), getContext())); Item next = null; while ((next = pathIter.next()) != null) { vals.add(getValue(proColumn.getSymbol().getType().getComponentType(), next, this.table.getXQueryExpression().getConfig(), getContext()));
jj_consume_token(FOR); jj_consume_token(ORDINALITY); {if (true) return new XMLTable.XMLColumn(name);} break; case STRING: {if (true) return new XMLTable.XMLColumn(name, datatype.type, path, defaultExpr);} break; default:
jj_consume_token(FOR); jj_consume_token(ORDINALITY); {if (true) return new XMLTable.XMLColumn(name);} break; case STRING: {if (true) return new XMLTable.XMLColumn(name, datatype.type, path, defaultExpr);} break; default:
jj_consume_token(FOR); jj_consume_token(ORDINALITY); {if (true) return new XMLTable.XMLColumn(name);} break; case STRING: {if (true) return new XMLTable.XMLColumn(name, datatype.type, path, defaultExpr);} break; default:
private PathMapRoot projectColumns(PathMapRoot parentRoot, List<XMLTable.XMLColumn> columns, PathMapNode finalNode, AnalysisRecord record) { for (XMLColumn xmlColumn : columns) { if (xmlColumn.isOrdinal()) { continue; Expression internalExpression = getXPathExpression(xmlColumn.getName()).getInternalExpression(); if (containsRootFunction(internalExpression)) { if (record.recordAnnotations()) { record.addAnnotation(XQUERY_PLANNING, "Root function used in column path " + xmlColumn.getPath(), "Document projection will not be used", Priority.MEDIUM); //$NON-NLS-1$ //$NON-NLS-2$ if (subContextRoot != null) { if (record.recordAnnotations()) { record.addAnnotation(XQUERY_PLANNING, "Multiple context items exist in column path " + xmlColumn.getPath(), "Document projection will not be used", Priority.MEDIUM); //$NON-NLS-1$ //$NON-NLS-2$
private PathMapRoot projectColumns(PathMapRoot parentRoot, List<XMLTable.XMLColumn> columns, PathMapNode finalNode, AnalysisRecord record) { for (XMLColumn xmlColumn : columns) { if (xmlColumn.isOrdinal()) { continue; Expression internalExpression = getXPathExpression(xmlColumn.getName()).getInternalExpression(); if (containsRootFunction(internalExpression)) { if (record.recordAnnotations()) { record.addAnnotation(XQUERY_PLANNING, "Root function used in column path " + xmlColumn.getPath(), "Document projection will not be used", Priority.MEDIUM); //$NON-NLS-1$ //$NON-NLS-2$ if (subContextRoot != null) { if (record.recordAnnotations()) { record.addAnnotation(XQUERY_PLANNING, "Multiple context items exist in column path " + xmlColumn.getPath(), "Document projection will not be used", Priority.MEDIUM); //$NON-NLS-1$ //$NON-NLS-2$
private PathMapRoot projectColumns(PathMapRoot parentRoot, List<XMLTable.XMLColumn> columns, PathMapNode finalNode, AnalysisRecord record) { for (XMLColumn xmlColumn : columns) { if (xmlColumn.isOrdinal()) { continue; Expression internalExpression = xmlColumn.getPathExpression().getInternalExpression(); PathMap subMap = new PathMap(internalExpression); PathMapRoot subContextRoot = null; if (subContextRoot != null) { if (record.recordAnnotations()) { record.addAnnotation(XQUERY_PLANNING, "Multiple context items exist in column path " + xmlColumn.getPath(), "Document projection will not be used", Priority.MEDIUM); //$NON-NLS-1$ //$NON-NLS-2$
if (axis != AxisInfo.NAMESPACE && axis != AxisInfo.ATTRIBUTE) { if (record.recordAnnotations()) { record.addAnnotation(XQUERY_PLANNING, "The column path contains an invalid reverse axis " + xmlColumn.getPath(), "Document streaming will not be used", Priority.MEDIUM); //$NON-NLS-1$ //$NON-NLS-2$ record.addAnnotation(XQUERY_PLANNING, "The column path contains an invalid reverse axis " + xmlColumn.getPath(), "Document streaming will not be used", Priority.MEDIUM); //$NON-NLS-1$ //$NON-NLS-2$ if (current.getTarget().isReturnable()) { if (record.recordAnnotations()) { record.addAnnotation(XQUERY_PLANNING, "The column path contains an invalid reverse axis " + xmlColumn.getPath(), "Document streaming will not be used", Priority.MEDIUM); //$NON-NLS-1$ //$NON-NLS-2$ } else { if (record.recordAnnotations()) { record.addAnnotation(XQUERY_PLANNING, "The column path may not reference an ancestor or subtree " + xmlColumn.getPath(), "Document streaming will not be used", Priority.MEDIUM); //$NON-NLS-1$ //$NON-NLS-2$
if (axis != AxisInfo.NAMESPACE && axis != AxisInfo.ATTRIBUTE) { if (record.recordAnnotations()) { record.addAnnotation(XQUERY_PLANNING, "The column path contains an invalid reverse axis " + xmlColumn.getPath(), "Document streaming will not be used", Priority.MEDIUM); //$NON-NLS-1$ //$NON-NLS-2$ record.addAnnotation(XQUERY_PLANNING, "The column path contains an invalid reverse axis " + xmlColumn.getPath(), "Document streaming will not be used", Priority.MEDIUM); //$NON-NLS-1$ //$NON-NLS-2$ if (current.getTarget().isReturnable()) { if (record.recordAnnotations()) { record.addAnnotation(XQUERY_PLANNING, "The column path contains an invalid reverse axis " + xmlColumn.getPath(), "Document streaming will not be used", Priority.MEDIUM); //$NON-NLS-1$ //$NON-NLS-2$ } else { if (record.recordAnnotations()) { record.addAnnotation(XQUERY_PLANNING, "The column path may not reference an ancestor or subtree " + xmlColumn.getPath(), "Document streaming will not be used", Priority.MEDIUM); //$NON-NLS-1$ //$NON-NLS-2$
XMLColumn col = cols.next(); append(SPACE); outputDisplayName(col.getName()); append(SPACE); if (col.isOrdinal()) { append(FOR); append(SPACE); append(NonReserved.ORDINALITY); } else { append(col.getType()); if (col.getDefaultExpression() != null) { append(SPACE); append(DEFAULT); append(SPACE); visitNode(col.getDefaultExpression()); if (col.getPath() != null) { append(SPACE); append(NonReserved.PATH); append(SPACE); visitNode(new Constant(col.getPath()));
List<Object> tuple = new ArrayList<Object>(projectedColumns.size()); for (XMLColumn proColumn : projectedColumns) { if (proColumn.isOrdinal()) { if (rowCount > Integer.MAX_VALUE) { throw new TeiidRuntimeException(new TeiidProcessingException(QueryPlugin.Event.TEIID31174, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31174))); } else { try { XPathExpression path = table.getXQueryExpression().getXPathExpression(proColumn.getName()); XPathDynamicContext dynamicContext = path.createDynamicContext(item); final SequenceIterator pathIter = path.iterate(dynamicContext); Item colItem = pathIter.next(); if (colItem == null) { if (proColumn.getDefaultExpression() != null) { tuple.add(getEvaluator(Collections.emptyMap()).evaluate(proColumn.getDefaultExpression(), null)); } else { tuple.add(null); if (proColumn.getSymbol().getType() == DataTypeManager.DefaultDataClasses.XML) { SequenceIterator pushBack = new PushBackSequenceIterator(pathIter, colItem); XMLType value = table.getXQueryExpression().createXMLType(pushBack, this.getBufferManager(), false, getContext()); if (proColumn.getSymbol().getType().isArray()) { ArrayList<Object> vals = new ArrayList<Object>(); vals.add(getValue(proColumn.getSymbol().getType().getComponentType(), colItem, this.table.getXQueryExpression().getConfig(), getContext())); Item next = null; while ((next = pathIter.next()) != null) { vals.add(getValue(proColumn.getSymbol().getType().getComponentType(), next, this.table.getXQueryExpression().getConfig(), getContext()));
if (axis != AxisInfo.NAMESPACE && axis != AxisInfo.ATTRIBUTE) { if (record.recordAnnotations()) { record.addAnnotation(XQUERY_PLANNING, "The column path contains an invalid reverse axis " + xmlColumn.getPath(), "Document streaming will not be used", Priority.MEDIUM); //$NON-NLS-1$ //$NON-NLS-2$ record.addAnnotation(XQUERY_PLANNING, "The column path contains an invalid reverse axis " + xmlColumn.getPath(), "Document streaming will not be used", Priority.MEDIUM); //$NON-NLS-1$ //$NON-NLS-2$ if (current.getTarget().isReturnable()) { if (record.recordAnnotations()) { record.addAnnotation(XQUERY_PLANNING, "The column path contains an invalid reverse axis " + xmlColumn.getPath(), "Document streaming will not be used", Priority.MEDIUM); //$NON-NLS-1$ //$NON-NLS-2$ } else { if (record.recordAnnotations()) { record.addAnnotation(XQUERY_PLANNING, "The column path may not reference an ancestor or subtree " + xmlColumn.getPath(), "Document streaming will not be used", Priority.MEDIUM); //$NON-NLS-1$ //$NON-NLS-2$
XMLColumn col = cols.next(); append(SPACE); outputDisplayName(col.getName()); append(SPACE); if (col.isOrdinal()) { append(FOR); append(SPACE); append(NonReserved.ORDINALITY); } else { append(col.getType()); if (col.getDefaultExpression() != null) { append(SPACE); append(DEFAULT); append(SPACE); visitNode(col.getDefaultExpression()); if (col.getPath() != null) { append(SPACE); append(NonReserved.PATH); append(SPACE); visitNode(new Constant(col.getPath()));
List<Object> tuple = new ArrayList<Object>(projectedColumns.size()); for (XMLColumn proColumn : projectedColumns) { if (proColumn.isOrdinal()) { if (rowCount > Integer.MAX_VALUE) { throw new TeiidRuntimeException(new TeiidProcessingException(QueryPlugin.Event.TEIID31174, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31174))); } else { try { XPathExpression path = proColumn.getPathExpression(); XPathDynamicContext dynamicContext = path.createDynamicContext(item); SequenceIterator pathIter = path.iterate(dynamicContext); Item colItem = pathIter.next(); if (colItem == null) { if (proColumn.getDefaultExpression() != null) { tuple.add(getEvaluator(Collections.emptyMap()).evaluate(proColumn.getDefaultExpression(), null)); } else { tuple.add(null); if (proColumn.getSymbol().getType() == DataTypeManager.DefaultDataClasses.XML) { XMLType value = table.getXQueryExpression().createXMLType(pathIter.getAnother(), this.getBufferManager(), false, getContext()); tuple.add(value); continue; if (proColumn.getSymbol().getType().isArray()) { ArrayList<Object> vals = new ArrayList<Object>(); vals.add(getValue(proColumn.getSymbol().getType().getComponentType(), colItem, this.table.getXQueryExpression().getConfig(), getContext())); Item next = null; while ((next = pathIter.next()) != null) { vals.add(getValue(proColumn.getSymbol().getType().getComponentType(), next, this.table.getXQueryExpression().getConfig(), getContext()));
XMLColumn col = cols.next(); append(SPACE); outputDisplayName(col.getName()); append(SPACE); if (col.isOrdinal()) { append(FOR); append(SPACE); append(NonReserved.ORDINALITY); } else { append(col.getType()); if (col.getDefaultExpression() != null) { append(SPACE); append(DEFAULT); append(SPACE); visitNode(col.getDefaultExpression()); if (col.getPath() != null) { append(SPACE); append(NonReserved.PATH); append(SPACE); visitNode(new Constant(col.getPath()));
eval.setStaticContext(ic); for (XMLColumn xmlColumn : columns) { if (xmlColumn.isOrdinal()) { continue; String path = xmlColumn.getPath(); if (path == null) { path = xmlColumn.getName(); exp = eval.createExpression(path); } catch (XPathException e) { throw new QueryResolverException(QueryPlugin.Event.TEIID30155, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30155, xmlColumn.getName(), xmlColumn.getPath())); this.columnMap.put(xmlColumn.getName(), exp);
eval.setStaticContext(ic); for (XMLColumn xmlColumn : columns) { if (xmlColumn.isOrdinal()) { continue; String path = xmlColumn.getPath(); if (path == null) { path = xmlColumn.getName(); exp = eval.createExpression(path); } catch (XPathException e) { throw new QueryResolverException(QueryPlugin.Event.TEIID30155, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30155, xmlColumn.getName(), xmlColumn.getPath())); this.columnMap.put(xmlColumn.getName(), exp);
eval.setStaticContext(ic); for (XMLColumn xmlColumn : columns) { if (xmlColumn.isOrdinal()) { continue; String path = xmlColumn.getPath(); if (path == null) { path = xmlColumn.getName(); exp = eval.createExpression(path); } catch (XPathException e) { throw new QueryResolverException(QueryPlugin.Event.TEIID30155, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30155, xmlColumn.getName(), xmlColumn.getPath())); xmlColumn.setPathExpression(exp);