Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
import io.trino.plugin.jdbc.JdbcColumnHandle;
import io.trino.plugin.jdbc.JdbcExpression;
import io.trino.plugin.jdbc.expression.AggregateFunctionRule;
import io.trino.plugin.jdbc.expression.AggregateFunctionRule.RewriteContext;
import io.trino.spi.connector.AggregateFunction;
import io.trino.spi.expression.Variable;
import io.trino.spi.type.DoubleType;

import java.util.Optional;

import static com.google.common.base.Verify.verify;
import static com.google.common.base.Verify.verifyNotNull;
import static io.trino.matching.Capture.newCapture;
import static io.trino.plugin.jdbc.expression.AggregateFunctionPatterns.basicAggregation;
import static io.trino.plugin.jdbc.expression.AggregateFunctionPatterns.expressionType;
Expand All @@ -44,18 +46,19 @@ public class ImplementSqlServerStddevPop
public Pattern<AggregateFunction> getPattern()
{
return basicAggregation()
.with(functionName().equalTo("stddev_pop"))
.with(functionName().matching(name -> name.equalsIgnoreCase("stddev_pop")))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see .with(functionName().equalto 10 times in the codebase.

We should rather change the functionName().equalto impl, that "workaround" it in every place

Copy link
Copy Markdown
Member Author

@hashhar hashhar Jan 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm creating a new PR for just the comments added to SqlServerClient about the missing pushdowns.

Will update this PR with suggested changes before the upcoming release.

.with(singleInput().matching(
variable()
.with(expressionType().matching(DoubleType.class::isInstance))
.capturedAs(INPUT)));
}

@Override
public Optional<JdbcExpression> rewrite(AggregateFunction aggregateFunction, Captures captures, AggregateFunctionRule.RewriteContext context)
public Optional<JdbcExpression> rewrite(AggregateFunction aggregateFunction, Captures captures, RewriteContext context)
{
Variable input = captures.get(INPUT);
JdbcColumnHandle columnHandle = (JdbcColumnHandle) context.getAssignment(input.getName());
verifyNotNull(columnHandle, "Unbound variable: %s", input);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant, already checked by ontext.getAssignment

verify(columnHandle.getColumnType().equals(DOUBLE));
verify(aggregateFunction.getOutputType().equals(DOUBLE));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.Optional;

import static com.google.common.base.Verify.verify;
import static com.google.common.base.Verify.verifyNotNull;
import static io.trino.matching.Capture.newCapture;
import static io.trino.plugin.jdbc.expression.AggregateFunctionPatterns.basicAggregation;
import static io.trino.plugin.jdbc.expression.AggregateFunctionPatterns.expressionType;
Expand Down Expand Up @@ -59,6 +60,7 @@ public Optional<JdbcExpression> rewrite(AggregateFunction aggregateFunction, Cap
{
Variable input = captures.get(INPUT);
JdbcColumnHandle columnHandle = (JdbcColumnHandle) context.getAssignment(input.getName());
verifyNotNull(columnHandle, "Unbound variable: %s", input);
verify(columnHandle.getColumnType().equals(DOUBLE));
verify(aggregateFunction.getOutputType().equals(DOUBLE));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.Optional;

import static com.google.common.base.Verify.verify;
import static com.google.common.base.Verify.verifyNotNull;
import static io.trino.matching.Capture.newCapture;
import static io.trino.plugin.jdbc.expression.AggregateFunctionPatterns.basicAggregation;
import static io.trino.plugin.jdbc.expression.AggregateFunctionPatterns.expressionType;
Expand Down Expand Up @@ -59,6 +60,7 @@ public Optional<JdbcExpression> rewrite(AggregateFunction aggregateFunction, Cap
{
Variable input = captures.get(INPUT);
JdbcColumnHandle columnHandle = (JdbcColumnHandle) context.getAssignment(input.getName());
verifyNotNull(columnHandle, "Unbound variable: %s", input);
verify(columnHandle.getColumnType().equals(DOUBLE));
verify(aggregateFunction.getOutputType().equals(DOUBLE));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Optional;

import static com.google.common.base.Verify.verify;
import static com.google.common.base.Verify.verifyNotNull;
import static io.trino.matching.Capture.newCapture;
import static io.trino.plugin.jdbc.expression.AggregateFunctionPatterns.basicAggregation;
import static io.trino.plugin.jdbc.expression.AggregateFunctionPatterns.expressionType;
Expand All @@ -44,7 +45,7 @@ public class ImplementSqlServerVariancePop
public Pattern<AggregateFunction> getPattern()
{
return basicAggregation()
.with(functionName().equalTo("var_pop"))
.with(functionName().matching(name -> name.equalsIgnoreCase("var_pop")))
.with(singleInput().matching(
variable()
.with(expressionType().matching(DoubleType.class::isInstance))
Expand All @@ -56,6 +57,7 @@ public Optional<JdbcExpression> rewrite(AggregateFunction aggregateFunction, Cap
{
Variable input = captures.get(INPUT);
JdbcColumnHandle columnHandle = (JdbcColumnHandle) context.getAssignment(input.getName());
verifyNotNull(columnHandle, "Unbound variable: %s", input);
verify(columnHandle.getColumnType().equals(DOUBLE));
verify(aggregateFunction.getOutputType().equals(DOUBLE));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public SqlServerClient(BaseJdbcConfig config, ConnectionFactory connectionFactor
.add(new ImplementSqlServerStddevPop())
.add(new ImplementSqlServerVariance())
.add(new ImplementSqlServerVariancePop())
// SQL Server doesn't have covar_samp and covar_pop functions so we can't implement pushdown for them
.build());
}

Expand Down