Skip to content

Commit

Permalink
BZ1580449: DV 6.4.4 + Revert "TEIID-4455: Change planning step for fr…
Browse files Browse the repository at this point in the history
…om_unixtime() pushdown"

This reverts commit 02ddb48.
  • Loading branch information
johnathonlee committed Sep 4, 2018
1 parent 2416237 commit 24b811c
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 165 deletions.
Expand Up @@ -146,7 +146,6 @@ public class SourceSystemFunctions {
public static final String TIMESTAMPDIFF = "timestampdiff"; //$NON-NLS-1$
public static final String WEEK = "week"; //$NON-NLS-1$
public static final String YEAR = "year"; //$NON-NLS-1$
public static final String FROM_UNIXTIME = "from_unixtime"; //$NON-NLS-1$

//system functions
public static final String IFNULL = "ifnull"; //$NON-NLS-1$
Expand Down
Expand Up @@ -227,9 +227,6 @@ <h4 class="western">from ${project.version}</h4>
<li/>
<p style="margin-bottom: 0in">
<a href='https://issues.jboss.org/browse/TEIID-2476'>TEIID-2476</a> - Exclude hidden tables/columns from metadata (filtering metadata based upon data roles, improving the performance of pg system queries, allowing admin access to see everything, adding a test for properties, expanding the check of key records)
<li/>
<p style="margin-bottom: 0in">
<a href='https://issues.jboss.org/browse/TEIID-4455'>TEIID-4455</a> - Impala Translator - Change planning step for from_unixtime() pushdown (Change planning step for from_unixtime() pushdown)
<li/>
<p style="margin-bottom: 0in">
<a href='https://issues.jboss.org/browse/TEIID-4512'>TEIID-4512</a> - Issue with older drivers and useStreamsForLobs (calling the old method if possible)
Expand Down
Expand Up @@ -146,7 +146,6 @@ public List<String> getSupportedFunctions() {
supportedFunctions.add(SourceSystemFunctions.CURTIME);
supportedFunctions.add(SourceSystemFunctions.DEGREES);
supportedFunctions.add(SourceSystemFunctions.DAYOFMONTH);
supportedFunctions.add(SourceSystemFunctions.FROM_UNIXTIME);
supportedFunctions.add(SourceSystemFunctions.EXP);
supportedFunctions.add(SourceSystemFunctions.FLOOR);
supportedFunctions.add(SourceSystemFunctions.HOUR);
Expand Down
Expand Up @@ -146,7 +146,6 @@ public List<String> getSupportedFunctions() {
supportedFunctions.add(SourceSystemFunctions.DAYNAME);
supportedFunctions.add(SourceSystemFunctions.DAYOFMONTH);
supportedFunctions.add(SourceSystemFunctions.DAYOFWEEK);
supportedFunctions.add(SourceSystemFunctions.FROM_UNIXTIME);
supportedFunctions.add(SourceSystemFunctions.EXP);
supportedFunctions.add(SourceSystemFunctions.FLOOR);
supportedFunctions.add(SourceSystemFunctions.HOUR);
Expand Down
Expand Up @@ -204,7 +204,7 @@ public void start() throws TranslatorException {
addPushDownFunction(EXASOL, YEARS_BETWEEN, DOUBLE, DATE, DATE);
addPushDownFunction(EXASOL, YEARS_BETWEEN, DOUBLE, TIMESTAMP, TIMESTAMP);

registerFunctionModifier(SourceSystemFunctions.FROM_UNIXTIME, new AliasModifier(FROM_POSIX_TIME));
//registerFunctionModifier(SourceSystemFunctions.FROM_UNIXTIME, new AliasModifier(FROM_POSIX_TIME));
registerFunctionModifier(SourceSystemFunctions.DAYOFMONTH, new AliasModifier(DAY));
registerFunctionModifier(SourceSystemFunctions.FORMATTIMESTAMP, new AliasModifier(TO_CHAR));
registerFunctionModifier(SourceSystemFunctions.PARSETIMESTAMP, new AliasModifier(TO_TIMESTAMP));
Expand Down Expand Up @@ -294,7 +294,7 @@ public List<String> getSupportedFunctions() {

//Date
supportedFunctions.add(SourceSystemFunctions.CURDATE);
supportedFunctions.add(SourceSystemFunctions.FROM_UNIXTIME);
//supportedFunctions.add(SourceSystemFunctions.FROM_UNIXTIME);
supportedFunctions.add(SourceSystemFunctions.MONTH);
supportedFunctions.add(SourceSystemFunctions.NOW);
supportedFunctions.add(SourceSystemFunctions.PARSETIMESTAMP);
Expand Down
Expand Up @@ -159,7 +159,6 @@ public class ConnectorWorkItem implements ConnectorWork {
SourceCapabilities capabilities = manager.getCapabilities();
//set other properties once the capabilities have been obtained
factory.setSupportsConcat2(capabilities.supportsFunction(SourceSystemFunctions.CONCAT2));
factory.setSupportFromUnixtime(capabilities.supportsFunction(SourceSystemFunctions.FROM_UNIXTIME));
//read directly from the connector
factory.setConvertIn(!this.connector.supportsInCriteria());
factory.setMaxInPredicateSize((Integer) capabilities.getSourceProperty(Capability.MAX_IN_CRITERIA_SIZE));
Expand Down
Expand Up @@ -22,7 +22,6 @@

package org.teiid.dqp.internal.datamgr;

import java.sql.Timestamp;
import java.util.*;

import org.teiid.api.exception.query.QueryMetadataException;
Expand All @@ -38,7 +37,6 @@
import org.teiid.language.*;
import org.teiid.language.Argument.Direction;
import org.teiid.language.Comparison.Operator;
import org.teiid.language.SQLConstants.NonReserved;
import org.teiid.language.SortSpecification.Ordering;
import org.teiid.language.SubqueryComparison.Quantifier;
import org.teiid.language.DerivedColumn;
Expand All @@ -51,7 +49,6 @@
import org.teiid.metadata.Table;
import org.teiid.query.QueryPlugin;
import org.teiid.query.function.FunctionDescriptor;
import org.teiid.query.function.FunctionLibrary;
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.metadata.TempMetadataID;
import org.teiid.query.optimizer.relational.rules.RulePlaceAccess;
Expand Down Expand Up @@ -146,7 +143,6 @@ public void remove() {
private Map<String, List<? extends List<?>>> dependentSets;
private boolean convertIn;
private boolean supportsConcat2;
private boolean supportFromUnixtime;
private int maxInCriteriaSize;

//state to handle with name exclusion
Expand All @@ -172,10 +168,6 @@ public void setSupportsConcat2(boolean supportsConcat2) {
this.supportsConcat2 = supportsConcat2;
}

public void setSupportFromUnixtime(boolean supportFromUnixtime) {
this.supportFromUnixtime = supportFromUnixtime ;
}

public void setExcludeWithName(String excludeWithName) {
this.excludeWithName = excludeWithName;
}
Expand Down Expand Up @@ -793,15 +785,6 @@ org.teiid.language.Expression translate(Function function) {
caseExpr.setElseExpression(concat);
caseExpr.setType(DataTypeManager.DefaultDataClasses.STRING);
return translate(caseExpr);
} else if(!supportFromUnixtime && function.getFunctionDescriptor().getMethod().getParent() == null && name.equalsIgnoreCase(SourceSystemFunctions.FROM_UNIXTIME)) {
// from_unixtime(a) => timestampadd(SQL_TSI_SECOND, a, new Timestamp(0))
Function result = new Function(FunctionLibrary.TIMESTAMPADD, new Expression[] {new Constant(NonReserved.SQL_TSI_SECOND), function.getArg(0), new Constant(new Timestamp(0)) });
// resolve the function
FunctionDescriptor descriptor =
metadataFactory.getMetadata().getFunctionLibrary().findFunction(FunctionLibrary.TIMESTAMPADD, new Class[] { DataTypeManager.DefaultDataClasses.STRING, DataTypeManager.DefaultDataClasses.INTEGER, DataTypeManager.DefaultDataClasses.TIMESTAMP });
result.setFunctionDescriptor(descriptor);
result.setType(DataTypeManager.DefaultDataClasses.TIMESTAMP);
return translate(result);
}
//check for translator pushdown functions, and use the name in source if possible
if (function.getFunctionDescriptor().getMethod().getNameInSource() != null &&
Expand Down
Expand Up @@ -550,10 +550,6 @@ public static Object quarter(Date date) {
}
return Integer.valueOf(month/3 + 1);
}

public static Object from_unixtime(Integer count) {
return timestampAdd(NonReserved.SQL_TSI_SECOND, count, new Timestamp(0));
}

// ================== Function = timestampadd =====================

Expand Down
Expand Up @@ -1117,10 +1117,11 @@ private void addTimeZoneFunctions() {
}

private void addUnixTimeFunctions() {
functions.add(new FunctionMethod(SourceSystemFunctions.FROM_UNIXTIME, QueryPlugin.Util.getString("SystemSource.from_unixtime_description"), DATETIME, FUNCTION_CLASS, "from_unixtime", //$NON-NLS-1$ //$NON-NLS-2$
new FunctionParameter[]{
new FunctionParameter("unix_timestamp", DataTypeManager.DefaultDataTypes.INTEGER, QueryPlugin.Util.getString("SystemSource.from_unixtime_param1"))}, //$NON-NLS-1$ //$NON-NLS-2$
new FunctionParameter("result", DataTypeManager.DefaultDataTypes.TIMESTAMP, QueryPlugin.Util.getString("SystemSource.from_unixtime_result")))); //$NON-NLS-1$ //$NON-NLS-2$
functions.add(new FunctionMethod(FunctionLibrary.FROM_UNIXTIME, QueryPlugin.Util.getString("SystemSource.from_unixtime_description"), DATETIME, PushDown.SYNTHETIC, null, null, //$NON-NLS-1$
Arrays.asList(
new FunctionParameter("unix_timestamp", DataTypeManager.DefaultDataTypes.INTEGER, QueryPlugin.Util.getString("SystemSource.from_unixtime_param1")) //$NON-NLS-1$ //$NON-NLS-2$
),
new FunctionParameter("result", DataTypeManager.DefaultDataTypes.TIMESTAMP, QueryPlugin.Util.getString("SystemSource.from_unixtime_result")), true, Determinism.DETERMINISTIC )); //$NON-NLS-1$ //$NON-NLS-2$
}

private void addTypedNullIfFunction(String type) {
Expand Down
Expand Up @@ -252,18 +252,11 @@ public static boolean supportsScalarFunction(Object modelID, Function function,
// Find capabilities

if (!caps.supportsFunction(fullName)) {
if(SourceSystemFunctions.CONCAT2.equalsIgnoreCase(fullName)) {
//special handling for delayed rewrite of concat2
return (schema == null
&& caps.supportsFunction(SourceSystemFunctions.CONCAT)
&& caps.supportsFunction(SourceSystemFunctions.IFNULL)
&& caps.supportsCapability(Capability.QUERY_SEARCHED_CASE));
} else if(SourceSystemFunctions.FROM_UNIXTIME.equalsIgnoreCase(fullName)) {
return (schema == null
&& caps.supportsFunction(SourceSystemFunctions.TIMESTAMPADD));
} else {
return false ;
}
//special handling for delayed rewrite of concat2
return (schema == null && SourceSystemFunctions.CONCAT2.equalsIgnoreCase(fullName)
&& caps.supportsFunction(SourceSystemFunctions.CONCAT)
&& caps.supportsFunction(SourceSystemFunctions.IFNULL)
&& caps.supportsCapability(Capability.QUERY_SEARCHED_CASE));
}
if (FunctionLibrary.isConvert(function)) {
Class<?> fromType = function.getArg(0).getType();
Expand Down
11 changes: 9 additions & 2 deletions engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
Expand Up @@ -2556,8 +2556,15 @@ private Expression rewriteFunction(Function function) throws TeiidComponentExcep
function = result;
break;
}
case 1: {
// TEIID-4455
case 1: {//from_unixtime(a) => timestampadd(SQL_TSI_SECOND, a, new Timestamp(0))
Function result = new Function(FunctionLibrary.TIMESTAMPADD,
new Expression[] {new Constant(NonReserved.SQL_TSI_SECOND), function.getArg(0), new Constant(new Timestamp(0)) });
//resolve the function
FunctionDescriptor descriptor =
funcLibrary.findFunction(FunctionLibrary.TIMESTAMPADD, new Class[] { DataTypeManager.DefaultDataClasses.STRING, DataTypeManager.DefaultDataClasses.INTEGER, DataTypeManager.DefaultDataClasses.TIMESTAMP });
result.setFunctionDescriptor(descriptor);
result.setType(DataTypeManager.DefaultDataClasses.TIMESTAMP);
function = result;
break;
}
case 2: { // rewrite nullif(a, b) => case when (a = b) then null else a
Expand Down

This file was deleted.

Expand Up @@ -25,15 +25,12 @@
import static org.junit.Assert.*;
import static org.teiid.query.optimizer.TestOptimizer.*;

import java.sql.Timestamp;
import java.util.Arrays;
import java.util.List;
import java.util.TimeZone;

import org.junit.Test;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
import org.teiid.core.util.TimestampWithTimezone;
import org.teiid.dqp.internal.process.PreparedPlan;
import org.teiid.metadata.MetadataFactory;
import org.teiid.metadata.MetadataStore;
Expand Down Expand Up @@ -409,40 +406,6 @@ public QueryProcessor createQueryProcessor(String query,
new String[] {"SELECT concat2(g_0.e1, g_0.e1) FROM pm1.g1 AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
}

@Test
public void testFromUnitTime() throws Exception {
QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();

FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$

String sql = "SELECT from_unixtime(x.e2) from pm1.g1 as x"; //$NON-NLS-1$

// can pushdown
String expected = "SELECT from_unixtime(g_0.e2) FROM pm1.g1 AS g_0"; //$NON-NLS-1$
caps.setFunctionSupport(SourceSystemFunctions.FROM_UNIXTIME, true);
helpPlan(sql, metadata, null, capFinder, new String[] {expected}, ComparisonMode.EXACT_COMMAND_STRING);

// can not pushdown
expected = "SELECT g_0.e2 FROM pm1.g1 AS g_0"; //$NON-NLS-1$
caps.setFunctionSupport(SourceSystemFunctions.FROM_UNIXTIME, false);
ProcessorPlan plan = helpPlan(sql, metadata, null, capFinder, new String[] {expected}, ComparisonMode.EXACT_COMMAND_STRING);
HardcodedDataManager dataManager = new HardcodedDataManager();
dataManager.addData(expected, new List[] {Arrays.asList(1500000000)});
TimestampWithTimezone.resetCalendar(TimeZone.getTimeZone("GMT-06:00")); //$NON-NLS-1$
try {
TestProcessor.helpProcess(plan, dataManager, new List[] {Arrays.asList(Timestamp.valueOf("2017-07-13 20:40:00.0"))}); //$NON-NLS-1$
} finally {
TimestampWithTimezone.resetCalendar(null);
}

// will get replaced in the LanguageBridgeFactory
expected = "SELECT from_unixtime(g_0.e2) FROM pm1.g1 AS g_0"; //$NON-NLS-1$
caps.setFunctionSupport(SourceSystemFunctions.TIMESTAMPADD, true);
helpPlan(sql, metadata, null, capFinder, new String[] {expected}, ComparisonMode.EXACT_COMMAND_STRING);
}

@Test public void testPartialProjectPushdown() throws Exception {
QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();

Expand Down
Expand Up @@ -1437,35 +1437,12 @@ private void verifyProjectedTypesOnUnionBranches(String unionQuery, Class<?>[] t
@Test public void testRewriteFromUnixTime() throws Exception {
TimestampWithTimezone.resetCalendar(TimeZone.getTimeZone("GMT-06:00")); //$NON-NLS-1$
try {
helpTestRewriteCriteria("from_unixtime(pm1.g1.e2) = '1992-12-01 07:00:00'", "from_unixtime(pm1.g1.e2) = {ts'1992-12-01 07:00:00.0'}"); //$NON-NLS-1$ //$NON-NLS-2$
helpTestRewriteCriteria("from_unixtime(pm1.g1.e2) = '1992-12-01 07:00:00'", "timestampadd(SQL_TSI_SECOND, pm1.g1.e2, {ts'1969-12-31 18:00:00.0'}) = {ts'1992-12-01 07:00:00.0'}"); //$NON-NLS-1$ //$NON-NLS-2$
} finally {
TimestampWithTimezone.resetCalendar(null);
}
}

@Test
public void testRewriteFromUnixTime_1() throws Exception {
QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
TimestampWithTimezone.resetCalendar(TimeZone.getTimeZone("GMT-06:00")); //$NON-NLS-1$
try {
helpTestRewriteExpression("from_unixtime(pm1.g1.e2)", "from_unixtime(pm1.g1.e2)", metadata); //$NON-NLS-1$ //$NON-NLS-2$
} finally {
TimestampWithTimezone.resetCalendar(null);
}
}

@Test
public void testRewriteFromUnixTime_2() throws Exception {
QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
TimestampWithTimezone.resetCalendar(TimeZone.getTimeZone("GMT-06:00")); //$NON-NLS-1$
try {
helpTestRewriteExpression("from_unixtime(1500000000)", "{ts'2017-07-13 20:40:00.0'}", metadata); //$NON-NLS-1$ //$NON-NLS-2$
} finally {
TimestampWithTimezone.resetCalendar(null);
}
}


@Test public void testRewriteNullIf() throws Exception {
helpTestRewriteCriteria("nullif(pm1.g1.e2, pm1.g1.e4) = 1", "CASE WHEN pm1.g1.e2 = pm1.g1.e4 THEN convert(null, double) ELSE pm1.g1.e2 END = 1.0", true); //$NON-NLS-1$ //$NON-NLS-2$
}
Expand Down

0 comments on commit 24b811c

Please sign in to comment.