Skip to content

Commit

Permalink
TEIID-4202 added the initial mechanics for pushdown - with initial
Browse files Browse the repository at this point in the history
support pg and teiid
  • Loading branch information
shawkins committed May 13, 2016
1 parent 4ad7213 commit 6536e2a
Show file tree
Hide file tree
Showing 37 changed files with 486 additions and 50 deletions.
11 changes: 10 additions & 1 deletion api/src/main/java/org/teiid/language/Call.java
Expand Up @@ -34,12 +34,13 @@
/**
* Represents a procedural execution (such as a stored procedure).
*/
public class Call extends BaseLanguageObject implements Command, MetadataReference<Procedure> {
public class Call extends BaseLanguageObject implements Command, MetadataReference<Procedure>, TableReference {

private String name;
private List<Argument> arguments;
private Procedure metadataObject;
private Class<?> returnType;
private boolean tableReference;

public Call(String name, List<Argument> parameters, Procedure metadataObject) {
this.name = name;
Expand Down Expand Up @@ -109,5 +110,13 @@ public Class<?>[] getResultSetColumnTypes() {
}
return coulmnDTs;
}

public boolean isTableReference() {
return tableReference;
}

public void setTableReference(boolean tableReference) {
this.tableReference = tableReference;
}

}
9 changes: 9 additions & 0 deletions api/src/main/java/org/teiid/language/DerivedTable.java
Expand Up @@ -31,6 +31,7 @@ public class DerivedTable extends BaseLanguageObject implements TableReference {

private String correlationName;
private QueryExpression query;
private boolean lateral;

public DerivedTable(QueryExpression query, String name) {
this.query = query;
Expand All @@ -56,5 +57,13 @@ public void setQuery(QueryExpression query) {
public void acceptVisitor(LanguageObjectVisitor visitor) {
visitor.visit(this);
}

public boolean isLateral() {
return lateral;
}

public void setLateral(boolean lateral) {
this.lateral = lateral;
}

}
69 changes: 69 additions & 0 deletions api/src/main/java/org/teiid/language/NamedProcedureCall.java
@@ -0,0 +1,69 @@
/*
* JBoss, Home of Professional Open Source.
* See the COPYRIGHT.txt file distributed with this work for information
* regarding copyright ownership. Some portions may be licensed
* to Red Hat, Inc. under one or more contributor license agreements.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*/

package org.teiid.language;

import org.teiid.language.visitor.LanguageObjectVisitor;

/**
* Represents a procedure call that returns a table.
*/
public class NamedProcedureCall extends BaseLanguageObject implements TableReference {

private String correlationName;
private Call call;
private boolean lateral;

public NamedProcedureCall(Call call, String name) {
this.call = call;
this.correlationName = name;
}

public String getCorrelationName() {
return this.correlationName;
}

public void setCorrelationName(String name) {
this.correlationName = name;
}

public Call getCall() {
return this.call;
}

public void setCall(Call call) {
this.call = call;
}

public void acceptVisitor(LanguageObjectVisitor visitor) {
visitor.visit(this);
}

public boolean isLateral() {
return lateral;
}

public void setLateral(boolean lateral) {
this.lateral = lateral;
}

}
Expand Up @@ -123,4 +123,6 @@ public void visit(With obj) {}
public void visit(WithItem obj) {}
@Override
public void visit(Array array) {}
@Override
public void visit(NamedProcedureCall namedProcedureCall) {}
}
Expand Up @@ -200,6 +200,13 @@ public void visit(DerivedTable obj) {
}
}

@Override
public void visit(NamedProcedureCall namedProcedureCall) {
if (visitSubcommands) {
visitNode(namedProcedureCall.getCall());
}
}

@Override
public void visit(SetClause obj) {
visitNode(obj.getSymbol());
Expand Down
Expand Up @@ -67,4 +67,5 @@ public interface LanguageObjectVisitor {
public void visit(WindowSpecification windowSpecification);
public void visit(Parameter obj);
public void visit(Array array);
public void visit(NamedProcedureCall namedProcedureCall);
}
32 changes: 30 additions & 2 deletions api/src/main/java/org/teiid/language/visitor/SQLStringVisitor.java
Expand Up @@ -303,8 +303,7 @@ public static String getShortName(String elementName) {
}

public void visit(Call obj) {
buffer.append(EXEC)
.append(Tokens.SPACE);
appendCallStart(obj);

if(obj.getMetadataObject() != null) {
buffer.append(getName(obj.getMetadataObject()));
Expand All @@ -330,6 +329,11 @@ public void visit(Call obj) {
buffer.append(Tokens.RPAREN);
}

protected void appendCallStart(Call call) {
buffer.append(EXEC)
.append(Tokens.SPACE);
}

public void visit(Exists obj) {
buffer.append(EXISTS)
.append(Tokens.SPACE)
Expand Down Expand Up @@ -479,6 +483,10 @@ public void visit(In obj) {
}

public void visit(DerivedTable obj) {
if (obj.isLateral()) {
appendLateralKeyword();
buffer.append(Tokens.SPACE);
}
buffer.append(Tokens.LPAREN);
append(obj.getQuery());
buffer.append(Tokens.RPAREN);
Expand All @@ -490,6 +498,26 @@ public void visit(DerivedTable obj) {
buffer.append(obj.getCorrelationName());
}

protected void appendLateralKeyword() {
buffer.append(LATERAL);
}

public void visit(NamedProcedureCall obj) {
if (obj.isLateral()) {
appendLateralKeyword();
buffer.append(Tokens.SPACE);
}
buffer.append(Tokens.LPAREN);
append(obj.getCall());
buffer.append(Tokens.RPAREN);
buffer.append(Tokens.SPACE);
if(useAsInGroupAlias()) {
buffer.append(AS);
buffer.append(Tokens.SPACE);
}
buffer.append(obj.getCorrelationName());
}

public void visit(Insert obj) {
buffer.append(getInsertKeyword()).append(Tokens.SPACE);
appendSourceComment(obj);
Expand Down
Expand Up @@ -544,4 +544,16 @@ public org.teiid.translator.ExecutionFactory.TransactionSupport getTransactionSu
public String getExcludedCommonTableExpressionName() {
return delegate.getExcludedCommonTableExpressionName();
}
@Override
public boolean supportsLateralJoin() {
return delegate.supportsLateralJoin();
}
@Override
public boolean supportsLateralJoinCondition() {
return delegate.supportsLateralJoinCondition();
}
@Override
public boolean supportsProcedureTable() {
return delegate.supportsProcedureTable();
}
}
24 changes: 24 additions & 0 deletions api/src/main/java/org/teiid/translator/ExecutionFactory.java
Expand Up @@ -1345,4 +1345,28 @@ public void setExcluedCommonTableExpressionName(
String excluedCommonTableExpressionName) {
this.excluedCommonTableExpressionName = excluedCommonTableExpressionName;
}

/**
*
* @return true if the source supports lateral join
*/
public boolean supportsLateralJoin() {
return false;
}

/**
*
* @return true if the source supports lateral join conditions
*/
public boolean supportsLateralJoinCondition() {
return supportsLateralJoin();
}

/**
*
* @return
*/
public boolean supportsProcedureTable() {
return false;
}
}
Expand Up @@ -1566,4 +1566,8 @@ public boolean useColumnNamesForGeneratedKeys() {
return false;
}

public String getLateralKeyword() {
return SQLConstants.Reserved.LATERAL;
}

}
Expand Up @@ -220,6 +220,11 @@ public void visit(Call obj) {
parseNativeQueryParts(nativeQuery, obj.getArguments(), buffer, this);
return;
}
}
if (obj.isTableReference()) {
usingBinding = false;
super.visit(obj);
return;
}
this.prepared = true;
/*
Expand Down Expand Up @@ -465,4 +470,9 @@ public void visit(GroupBy obj) {
super.visit(obj);
}

@Override
protected void appendLateralKeyword() {
buffer.append(this.executionFactory.getLateralKeyword());
}

}
Expand Up @@ -97,6 +97,7 @@ protected Object convertToken(String group) {
public static final Version EIGHT_3 = Version.getVersion("8.3"); //$NON-NLS-1$
public static final Version EIGHT_4 = Version.getVersion("8.4"); //$NON-NLS-1$
public static final Version NINE_0 = Version.getVersion("9.0"); //$NON-NLS-1$
public static final Version NINE_3 = Version.getVersion("9.3"); //$NON-NLS-1$
protected OracleFormatFunctionModifier parseModifier = new PostgreSQLFormatFunctionModifier("TO_TIMESTAMP(", true); //$NON-NLS-1$

//postgis versions
Expand Down Expand Up @@ -936,4 +937,9 @@ public String translateLiteralBinaryType(BinaryType obj) {
return "E'\\\\x" + obj + '\''; //$NON-NLS-1$
}

@Override
public boolean supportsLateralJoin() {
return getVersion().compareTo(NINE_3) >= 0;
}

}
Expand Up @@ -32,6 +32,7 @@
import java.util.List;

import org.teiid.core.types.JDBCSQLTypeInfo;
import org.teiid.language.SQLConstants;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.metadata.Column;
Expand All @@ -58,6 +59,7 @@ public class TeiidExecutionFactory extends JDBCExecutionFactory {
public static final Version SEVEN_4 = Version.getVersion("7.4"); //$NON-NLS-1$
public static final Version SEVEN_5 = Version.getVersion("7.5"); //$NON-NLS-1$
public static final Version SEVEN_6 = Version.getVersion("7.6"); //$NON-NLS-1$
public static final Version EIGHT_1 = Version.getVersion("8.1"); //$NON-NLS-1$
public static final Version EIGHT_3 = Version.getVersion("8.3"); //$NON-NLS-1$
public static final Version EIGHT_4 = Version.getVersion("8.4"); //$NON-NLS-1$
public static final Version EIGHT_5 = Version.getVersion("8.5"); //$NON-NLS-1$
Expand Down Expand Up @@ -442,4 +444,22 @@ protected void getGeometryMetadata(Column c, Connection conn,
};
}

@Override
public boolean supportsLateralJoin() {
return true;
}

@Override
public String getLateralKeyword() {
if (getVersion().compareTo(EIGHT_1) < 0) {
return SQLConstants.Reserved.TABLE;
}
return super.getLateralKeyword();
}

@Override
public boolean supportsProcedureTable() {
return true;
}

}
Expand Up @@ -545,4 +545,13 @@ public void defer_testPreparedStatementCreationWithLeftConstant() {
true);
}

@Test public void testProcedureTable() {
helpTestVisitor("create foreign table smallb (intkey integer, stringkey string); "
+ "create foreign procedure spTest5 (param integer) returns table(stringkey string options (nameinsource 'other'), intkey integer)",
"select smallb.intkey, x.stringkey, x.intkey "
+ "from smallb left outer join lateral (exec spTest5(smallb.intkey)) as x on (true)",
"SELECT smallb.intkey, x.other, x.intkey FROM smallb LEFT OUTER JOIN LATERAL (EXEC spTest5(smallb.intkey)) AS x ON 1 = 1", //$NON-NLS-1$
true);
}

}
Expand Up @@ -126,6 +126,9 @@ public static BasicSourceCapabilities convertCapabilities(ExecutionFactory srcCa
tgtCaps.setCapabilitySupport(Capability.SUBQUERY_COMMON_TABLE_EXPRESSIONS, srcCaps.supportsSubqueryCommonTableExpressions());
tgtCaps.setCapabilitySupport(Capability.SUBQUERY_CORRELATED_LIMIT, srcCaps.supportsCorrelatedSubqueryLimit());
tgtCaps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR_PROJECTION, srcCaps.supportsScalarSubqueryProjection());
tgtCaps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_LATERAL, srcCaps.supportsLateralJoin());
tgtCaps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_LATERAL_CONDITION, srcCaps.supportsLateralJoin() && srcCaps.supportsLateralJoinCondition());
tgtCaps.setCapabilitySupport(Capability.QUERY_FROM_PROCEDURE_TABLE, srcCaps.supportsProcedureTable());
if (srcCaps.supportsPartialFiltering()) {
//disable supports that could end up being not filterable
tgtCaps.setCapabilitySupport(Capability.PARTIAL_FILTERS, true);
Expand Down

0 comments on commit 6536e2a

Please sign in to comment.