Skip to content

Commit

Permalink
Refactor SqlLifecycle into statement classes (apache#12845)
Browse files Browse the repository at this point in the history
* Refactor SqlLifecycle into statement classes

Create direct & prepared statements
Remove redundant exceptions from tests
Tidy up Calcite query tests
Make PlannerConfig more testable

* Build fixes

* Added builder to SqlQueryPlus

* Moved Calcites system properties to saffron.properties

* Build fix

* Resolve merge conflict

* Fix IntelliJ inspection issue

* Revisions from reviews

Backed out a revision to Calcite tests that didn't work out as planned

* Build fix

* Fixed spelling errors

* Fixed failed test

Prepare now enforces security; before it did not.

* Rebase and fix IntelliJ inspections issue

* Clean up exception handling

* Fix handling of JDBC auth errors

* Build fix

* More tweaks to security messages
  • Loading branch information
paul-rogers authored Aug 14, 2022
1 parent 4d65c08 commit 41712b7
Show file tree
Hide file tree
Showing 76 changed files with 3,159 additions and 2,578 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import org.apache.druid.sql.calcite.expression.SqlOperatorConversion;
import org.apache.druid.sql.calcite.expression.builtin.QueryLookupOperatorConversion;
import org.apache.druid.sql.calcite.planner.CalciteRulesManager;
import org.apache.druid.sql.calcite.planner.Calcites;
import org.apache.druid.sql.calcite.planner.DruidOperatorTable;
import org.apache.druid.sql.calcite.planner.DruidPlanner;
import org.apache.druid.sql.calcite.planner.PlannerConfig;
Expand All @@ -75,6 +74,7 @@
import org.openjdk.jmh.infra.Blackhole;

import javax.annotation.Nullable;

import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand All @@ -92,7 +92,6 @@ public class SqlBenchmark
{
static {
NullHandling.initializeForTests();
Calcites.setSystemProperties();
}

private static final Logger log = new Logger(SqlBenchmark.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.apache.druid.server.security.AuthTestUtils;
import org.apache.druid.sql.calcite.SqlVectorizedExpressionSanityTest;
import org.apache.druid.sql.calcite.planner.CalciteRulesManager;
import org.apache.druid.sql.calcite.planner.Calcites;
import org.apache.druid.sql.calcite.planner.DruidPlanner;
import org.apache.druid.sql.calcite.planner.PlannerConfig;
import org.apache.druid.sql.calcite.planner.PlannerFactory;
Expand All @@ -65,6 +64,7 @@
import org.openjdk.jmh.infra.Blackhole;

import javax.annotation.Nullable;

import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
Expand All @@ -82,7 +82,6 @@ public class SqlExpressionBenchmark

static {
NullHandling.initializeForTests();
Calcites.setSystemProperties();
ExpressionProcessing.initializeForStrictBooleansTests(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import org.apache.druid.server.security.AuthTestUtils;
import org.apache.druid.sql.calcite.SqlVectorizedExpressionSanityTest;
import org.apache.druid.sql.calcite.planner.CalciteRulesManager;
import org.apache.druid.sql.calcite.planner.Calcites;
import org.apache.druid.sql.calcite.planner.DruidPlanner;
import org.apache.druid.sql.calcite.planner.PlannerConfig;
import org.apache.druid.sql.calcite.planner.PlannerFactory;
Expand All @@ -71,6 +70,7 @@
import org.openjdk.jmh.infra.Blackhole;

import javax.annotation.Nullable;

import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
Expand All @@ -85,7 +85,6 @@ public class SqlNestedDataBenchmark

static {
NullHandling.initializeForTests();
Calcites.setSystemProperties();
ExpressionProcessing.initializeForStrictBooleansTests(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public DruidOperatorTable createOperatorTable()
}

@Test
public void testComputingSketchOnNumericValues() throws Exception
public void testComputingSketchOnNumericValues()
{
cannotVectorize();

Expand Down Expand Up @@ -145,7 +145,7 @@ public void testComputingSketchOnNumericValues() throws Exception
}

@Test
public void testComputingSketchOnCastedString() throws Exception
public void testComputingSketchOnCastedString()
{
cannotVectorize();

Expand Down Expand Up @@ -185,7 +185,7 @@ public void testComputingSketchOnCastedString() throws Exception
}

@Test
public void testDefaultCompressionForTDigestGenerateSketchAgg() throws Exception
public void testDefaultCompressionForTDigestGenerateSketchAgg()
{
cannotVectorize();

Expand All @@ -211,7 +211,7 @@ public void testDefaultCompressionForTDigestGenerateSketchAgg() throws Exception
}

@Test
public void testComputingQuantileOnPreAggregatedSketch() throws Exception
public void testComputingQuantileOnPreAggregatedSketch()
{
cannotVectorize();

Expand Down Expand Up @@ -253,7 +253,7 @@ public void testComputingQuantileOnPreAggregatedSketch() throws Exception
}

@Test
public void testGeneratingSketchAndComputingQuantileOnFly() throws Exception
public void testGeneratingSketchAndComputingQuantileOnFly()
{
cannotVectorize();

Expand Down Expand Up @@ -308,7 +308,7 @@ public void testGeneratingSketchAndComputingQuantileOnFly() throws Exception
}

@Test
public void testQuantileOnNumericValues() throws Exception
public void testQuantileOnNumericValues()
{
cannotVectorize();

Expand Down Expand Up @@ -345,7 +345,7 @@ public void testQuantileOnNumericValues() throws Exception
}

@Test
public void testCompressionParamForTDigestQuantileAgg() throws Exception
public void testCompressionParamForTDigestQuantileAgg()
{
cannotVectorize();
testQuery(
Expand Down Expand Up @@ -383,7 +383,7 @@ public void testCompressionParamForTDigestQuantileAgg() throws Exception
}

@Test
public void testQuantileOnCastedString() throws Exception
public void testQuantileOnCastedString()
{
cannotVectorize();

Expand Down Expand Up @@ -436,7 +436,7 @@ public void testQuantileOnCastedString() throws Exception
}

@Test
public void testEmptyTimeseriesResults() throws Exception
public void testEmptyTimeseriesResults()
{
cannotVectorize();

Expand Down Expand Up @@ -468,7 +468,7 @@ public void testEmptyTimeseriesResults() throws Exception
}

@Test
public void testGroupByAggregatorDefaultValues() throws Exception
public void testGroupByAggregatorDefaultValues()
{
cannotVectorize();
testQuery(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public Iterable<? extends Module> getJacksonModules()
return Iterables.concat(super.getJacksonModules(), new HllSketchModule().getJacksonModules());
}

@SuppressWarnings("resource")
@Override
public SpecificSegmentsQuerySegmentWalker createQuerySegmentWalker() throws IOException
{
Expand Down Expand Up @@ -149,7 +150,7 @@ public DruidOperatorTable createOperatorTable()
}

@Test
public void testApproxCountDistinctHllSketch() throws Exception
public void testApproxCountDistinctHllSketch()
{
// Can't vectorize due to SUBSTRING expression.
cannotVectorize();
Expand Down Expand Up @@ -244,7 +245,7 @@ public void testApproxCountDistinctHllSketch() throws Exception


@Test
public void testAvgDailyCountDistinctHllSketch() throws Exception
public void testAvgDailyCountDistinctHllSketch()
{
// Can't vectorize due to outer query, which runs on an inline datasource.
cannotVectorize();
Expand Down Expand Up @@ -340,7 +341,7 @@ public void testAvgDailyCountDistinctHllSketch() throws Exception
}

@Test
public void testApproxCountDistinctHllSketchIsRounded() throws Exception
public void testApproxCountDistinctHllSketchIsRounded()
{
testQuery(
"SELECT"
Expand Down Expand Up @@ -376,7 +377,7 @@ public void testApproxCountDistinctHllSketchIsRounded() throws Exception
}

@Test
public void testHllSketchPostAggs() throws Exception
public void testHllSketchPostAggs()
{
final String sketchSummary = "### HLL SKETCH SUMMARY: \n"
+ " Log Config K : 12\n"
Expand Down Expand Up @@ -528,7 +529,7 @@ public void testHllSketchPostAggs() throws Exception
}

@Test
public void testtHllSketchPostAggsPostSort() throws Exception
public void testtHllSketchPostAggsPostSort()
{
final String sketchSummary = "### HLL SKETCH SUMMARY: \n"
+ " Log Config K : 12\n"
Expand Down Expand Up @@ -582,7 +583,7 @@ public void testtHllSketchPostAggsPostSort() throws Exception
}

@Test
public void testEmptyTimeseriesResults() throws Exception
public void testEmptyTimeseriesResults()
{
// timeseries with all granularity have a single group, so should return default results for given aggregators
testQuery(
Expand Down Expand Up @@ -620,7 +621,7 @@ public void testEmptyTimeseriesResults() throws Exception
}

@Test
public void testGroupByAggregatorDefaultValues() throws Exception
public void testGroupByAggregatorDefaultValues()
{
testQuery(
"SELECT\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public DruidOperatorTable createOperatorTable()
}

@Test
public void testQuantileOnFloatAndLongs() throws Exception
public void testQuantileOnFloatAndLongs()
{
testQuery(
"SELECT\n"
Expand Down Expand Up @@ -213,7 +213,7 @@ public void testQuantileOnFloatAndLongs() throws Exception
}

@Test
public void testQuantileOnComplexColumn() throws Exception
public void testQuantileOnComplexColumn()
{
testQuery(
"SELECT\n"
Expand Down Expand Up @@ -270,7 +270,7 @@ public void testQuantileOnComplexColumn() throws Exception
}

@Test
public void testQuantileOnCastedString() throws Exception
public void testQuantileOnCastedString()
{
final List<Object[]> expectedResults;
if (NullHandling.replaceWithDefault()) {
Expand Down Expand Up @@ -363,7 +363,7 @@ public void testQuantileOnCastedString() throws Exception
}

@Test
public void testQuantileOnInnerQuery() throws Exception
public void testQuantileOnInnerQuery()
{
final List<Object[]> expectedResults;
if (NullHandling.replaceWithDefault()) {
Expand Down Expand Up @@ -429,7 +429,7 @@ public void testQuantileOnInnerQuery() throws Exception
}

@Test
public void testQuantileOnInnerQuantileQuery() throws Exception
public void testQuantileOnInnerQuantileQuery()
{
ImmutableList.Builder<Object[]> builder = ImmutableList.builder();
builder.add(new Object[]{"", 1.0});
Expand Down Expand Up @@ -496,7 +496,7 @@ public void testQuantileOnInnerQuantileQuery() throws Exception
}

@Test
public void testDoublesSketchPostAggs() throws Exception
public void testDoublesSketchPostAggs()
{
testQuery(
"SELECT\n"
Expand Down Expand Up @@ -679,7 +679,7 @@ public void testDoublesSketchPostAggs() throws Exception
}

@Test
public void testDoublesSketchPostAggsPostSort() throws Exception
public void testDoublesSketchPostAggsPostSort()
{
testQuery(
"SELECT DS_GET_QUANTILE(y, 0.5), DS_GET_QUANTILE(y, 0.98) from ("
Expand Down Expand Up @@ -728,7 +728,7 @@ public void testDoublesSketchPostAggsPostSort() throws Exception
}

@Test
public void testEmptyTimeseriesResults() throws Exception
public void testEmptyTimeseriesResults()
{
testQuery(
"SELECT\n"
Expand Down Expand Up @@ -768,7 +768,7 @@ public void testEmptyTimeseriesResults() throws Exception
}

@Test
public void testGroupByAggregatorDefaultValues() throws Exception
public void testGroupByAggregatorDefaultValues()
{
testQuery(
"SELECT\n"
Expand Down Expand Up @@ -828,7 +828,7 @@ public void testGroupByAggregatorDefaultValues() throws Exception
}

@Test
public void testSuccessWithSmallMaxStreamLength() throws Exception
public void testSuccessWithSmallMaxStreamLength()
{
final Map<String, Object> context = new HashMap<>(QUERY_CONTEXT_DEFAULT);
context.put(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public DruidOperatorTable createOperatorTable()
}

@Test
public void testApproxCountDistinctThetaSketch() throws Exception
public void testApproxCountDistinctThetaSketch()
{
// Cannot vectorize due to SUBSTRING.
cannotVectorize();
Expand Down Expand Up @@ -265,7 +265,7 @@ public void testApproxCountDistinctThetaSketch() throws Exception
}

@Test
public void testAvgDailyCountDistinctThetaSketch() throws Exception
public void testAvgDailyCountDistinctThetaSketch()
{
// Can't vectorize due to outer query (it operates on an inlined data source, which cannot be vectorized).
cannotVectorize();
Expand Down Expand Up @@ -359,7 +359,7 @@ public void testAvgDailyCountDistinctThetaSketch() throws Exception
}

@Test
public void testThetaSketchPostAggs() throws Exception
public void testThetaSketchPostAggs()
{
final List<Object[]> expectedResults;

Expand Down Expand Up @@ -529,7 +529,7 @@ public void testThetaSketchPostAggs() throws Exception
}

@Test
public void testThetaSketchPostAggsPostSort() throws Exception
public void testThetaSketchPostAggsPostSort()
{
final String sql = "SELECT DS_THETA(dim2) as y FROM druid.foo ORDER BY THETA_SKETCH_ESTIMATE(DS_THETA(dim2)) DESC LIMIT 10";

Expand Down Expand Up @@ -579,7 +579,7 @@ public void testThetaSketchPostAggsPostSort() throws Exception
}

@Test
public void testEmptyTimeseriesResults() throws Exception
public void testEmptyTimeseriesResults()
{
testQuery(
"SELECT\n"
Expand Down Expand Up @@ -638,7 +638,7 @@ public void testEmptyTimeseriesResults() throws Exception
}

@Test
public void testGroupByAggregatorDefaultValues() throws Exception
public void testGroupByAggregatorDefaultValues()
{
testQuery(
"SELECT\n"
Expand Down
Loading

0 comments on commit 41712b7

Please sign in to comment.