Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix non-sqlcompat validation in CalciteWindowQueryTest #15086

Merged
merged 39 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
bd55afd
fixes
kgyrtkirk Oct 4, 2023
5cf1e2c
check for latest rewrite place
kgyrtkirk Oct 4, 2023
c4ff274
Revert "check for latest rewrite place"
kgyrtkirk Oct 4, 2023
89844e9
some stuff
kgyrtkirk Oct 4, 2023
ed5d100
update test output
kgyrtkirk Oct 4, 2023
2a4a3ab
updates to test ouptuts
kgyrtkirk Oct 4, 2023
02aac9d
some stuff
kgyrtkirk Oct 4, 2023
a9877c4
move validator
kgyrtkirk Oct 4, 2023
f104ce4
cleanup
kgyrtkirk Oct 4, 2023
145fe82
fix
kgyrtkirk Oct 4, 2023
761cd68
change test slightly
kgyrtkirk Oct 4, 2023
a10fe7a
add apidoc cleanup warnings
kgyrtkirk Oct 4, 2023
6082df5
cleanup/etc
kgyrtkirk Oct 4, 2023
34a6aeb
instead of telling the story; add a fail with some reason whats the i…
kgyrtkirk Oct 4, 2023
9b74ef5
Merge remote-tracking branch 'apache/master' into windowing-fix-test-cmp
kgyrtkirk Oct 4, 2023
e376ae9
lead-lag fix
kgyrtkirk Oct 4, 2023
1acd53b
add test
kgyrtkirk Oct 5, 2023
a708ef2
remove unnecessary throw
kgyrtkirk Oct 5, 2023
8fa0664
druidexception-trial
kgyrtkirk Oct 5, 2023
b484606
Revert "druidexception-trial"
kgyrtkirk Oct 5, 2023
2858ff6
undo changes to no_grouping; add no_grouping2
kgyrtkirk Oct 5, 2023
2e91d7c
Merge remote-tracking branch 'apache/master' into windowing-fix-test-cmp
kgyrtkirk Oct 6, 2023
9a80c89
add missing assert on resultcount
kgyrtkirk Oct 6, 2023
ee2b35d
rename method; update
kgyrtkirk Oct 9, 2023
4e216b7
introduce enum/etc
kgyrtkirk Oct 9, 2023
5d0fcc0
make resultmatchmode accessible from TestBuilder#expectedResults
kgyrtkirk Oct 9, 2023
0ddd3be
fix dump results to use log
kgyrtkirk Oct 9, 2023
4073f5e
Merge remote-tracking branch 'apache/master' into windowing-fix-test-cmp
kgyrtkirk Oct 10, 2023
47e81d8
Merge remote-tracking branch 'apache/master' into windowing-fix-test-cmp
kgyrtkirk Oct 10, 2023
edea152
fix
kgyrtkirk Oct 10, 2023
de099c6
handle null correctly
kgyrtkirk Oct 10, 2023
e018b2c
disable feature type based things for MSQ
kgyrtkirk Oct 10, 2023
a74a9fd
fix varianssqlaggtest
kgyrtkirk Oct 10, 2023
185b8e7
use eps in other test
kgyrtkirk Oct 10, 2023
ed1bb89
fix intellij error
kgyrtkirk Oct 10, 2023
91b1be9
add final
kgyrtkirk Oct 11, 2023
df73774
addrss review
kgyrtkirk Oct 11, 2023
7714e2f
update test/string/etc
kgyrtkirk Oct 11, 2023
78d1d31
write concat in 3 lines :D
kgyrtkirk Oct 11, 2023
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 @@ -53,7 +53,6 @@
import org.apache.druid.sql.calcite.util.TestDataBuilder;
import org.apache.druid.timeline.DataSegment;
import org.apache.druid.timeline.partition.LinearShardSpec;
import org.junit.Assert;
import org.junit.Test;

import java.io.IOException;
Expand Down Expand Up @@ -130,6 +129,7 @@ public void testComputingSketchOnNumericValues()
.context(QUERY_CONTEXT_DEFAULT)
.build()
),
ResultMatchMode.EQUALS_EPS,
ImmutableList.of(
new String[]{
"\"AAAAAT/wAAAAAAAAQBgAAAAAAABAaQAAAAAAAAAAAAY/8AAAAAAAAD/wAAAAAAAAP/AAAAAAAABAAAAAAAAAAD/wAAAAAAAAQAgAAAAAAAA/8AAAAAAAAEAQAAAAAAAAP/AAAAAAAABAFAAAAAAAAD/wAAAAAAAAQBgAAAAAAAA=\""
Expand Down Expand Up @@ -166,6 +166,7 @@ public void testComputingSketchOnCastedString()
.context(QUERY_CONTEXT_DEFAULT)
.build()
),
ResultMatchMode.EQUALS_EPS,
ImmutableList.of(
NullHandling.replaceWithDefault()
? new String[]{
Expand Down Expand Up @@ -198,6 +199,7 @@ public void testDefaultCompressionForTDigestGenerateSketchAgg()
.context(QUERY_CONTEXT_DEFAULT)
.build()
),
ResultMatchMode.EQUALS_EPS,
ImmutableList.of(
new Object[]{"\"AAAAAT/wAAAAAAAAQBgAAAAAAABAWQAAAAAAAAAAAAY/8AAAAAAAAD/wAAAAAAAAP/AAAAAAAABAAAAAAAAAAD/wAAAAAAAAQAgAAAAAAAA/8AAAAAAAAEAQAAAAAAAAP/AAAAAAAABAFAAAAAAAAD/wAAAAAAAAQBgAAAAAAAA=\""}
)
Expand Down Expand Up @@ -242,6 +244,7 @@ public void testComputingQuantileOnPreAggregatedSketch()
.context(QUERY_CONTEXT_DEFAULT)
.build()
),
ResultMatchMode.EQUALS_EPS,
expectedResults
);
}
Expand Down Expand Up @@ -297,6 +300,7 @@ public void testGeneratingSketchAndComputingQuantileOnFly()
.setContext(QUERY_CONTEXT_DEFAULT)
.build()
),
ResultMatchMode.EQUALS_EPS,
expectedResults
);
}
Expand Down Expand Up @@ -334,6 +338,7 @@ public void testQuantileOnNumericValues()
.context(QUERY_CONTEXT_DEFAULT)
.build()
),
ResultMatchMode.EQUALS_EPS,
expectedResults
);
}
Expand Down Expand Up @@ -370,6 +375,7 @@ public void testCompressionParamForTDigestQuantileAgg()
.context(QUERY_CONTEXT_DEFAULT)
.build()
),
ResultMatchMode.EQUALS_EPS,
ImmutableList.of(
new Object[]{1.0, 3.5, 6.0}
)
Expand Down Expand Up @@ -421,6 +427,7 @@ public void testQuantileOnCastedString()
.context(QUERY_CONTEXT_DEFAULT)
.build()
),
ResultMatchMode.EQUALS_EPS,
ImmutableList.of(
NullHandling.replaceWithDefault()
? new Object[]{0.0, 0.5, 10.1}
Expand Down Expand Up @@ -455,6 +462,7 @@ public void testEmptyTimeseriesResults()
.context(QUERY_CONTEXT_DEFAULT)
.build()
),
ResultMatchMode.EQUALS_EPS,
ImmutableList.of(
new Object[]{"\"AAAAAX/wAAAAAAAA//AAAAAAAABAWQAAAAAAAAAAAAA=\"", Double.NaN}
)
Expand Down Expand Up @@ -499,32 +507,13 @@ public void testGroupByAggregatorDefaultValues()
.setContext(QUERY_CONTEXT_DEFAULT)
.build()
),
ResultMatchMode.EQUALS_EPS,
ImmutableList.of(
new Object[]{"a", "\"AAAAAX/wAAAAAAAA//AAAAAAAABAWQAAAAAAAAAAAAA=\"", Double.NaN}
)
);
}

@Override
public void assertResultsEquals(String sql, List<Object[]> expectedResults, List<Object[]> results)
{
Assert.assertEquals(expectedResults.size(), results.size());
for (int i = 0; i < expectedResults.size(); i++) {
Object[] expectedResult = expectedResults.get(i);
Object[] result = results.get(i);
Assert.assertEquals(expectedResult.length, result.length);
for (int j = 0; j < expectedResult.length; j++) {
if (expectedResult[j] instanceof Float) {
Assert.assertEquals((Float) expectedResult[j], (Float) result[j], 0.000001);
} else if (expectedResult[j] instanceof Double) {
Assert.assertEquals((Double) expectedResult[j], (Double) result[j], 0.000001);
} else {
Assert.assertEquals(expectedResult[j], result[j]);
}
}
}
}

private static PostAggregator makeFieldAccessPostAgg(String name)
{
return new FieldAccessPostAggregator(name, name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
import org.apache.druid.sql.calcite.util.TestDataBuilder;
import org.apache.druid.timeline.DataSegment;
import org.apache.druid.timeline.partition.LinearShardSpec;
import org.junit.Assert;
import org.junit.Test;

import java.io.IOException;
Expand Down Expand Up @@ -196,6 +195,7 @@ public void testVarPop()
.context(BaseCalciteQueryTest.QUERY_CONTEXT_DEFAULT)
.build()
),
ResultMatchMode.EQUALS_EPS,
expectedResults
);
}
Expand Down Expand Up @@ -243,6 +243,7 @@ public void testVarSamp()
.context(BaseCalciteQueryTest.QUERY_CONTEXT_DEFAULT)
.build()
),
ResultMatchMode.EQUALS_EPS,
expectedResults
);
}
Expand Down Expand Up @@ -298,6 +299,7 @@ public void testStdDevPop()
.context(BaseCalciteQueryTest.QUERY_CONTEXT_DEFAULT)
.build()
),
ResultMatchMode.EQUALS_EPS,
expectedResults
);
}
Expand Down Expand Up @@ -351,6 +353,7 @@ public void testStdDevSamp()
.context(BaseCalciteQueryTest.QUERY_CONTEXT_DEFAULT)
.build()
),
ResultMatchMode.EQUALS_EPS,
expectedResults
);
}
Expand Down Expand Up @@ -409,6 +412,7 @@ public void testStdDevWithVirtualColumns()
.context(BaseCalciteQueryTest.QUERY_CONTEXT_DEFAULT)
.build()
),
ResultMatchMode.EQUALS_EPS,
expectedResults
);
}
Expand Down Expand Up @@ -455,6 +459,7 @@ public void testVarianceOrderBy()
.setContext(BaseCalciteQueryTest.QUERY_CONTEXT_DEFAULT)
.build()
),
ResultMatchMode.EQUALS_EPS,
expectedResults
);
}
Expand Down Expand Up @@ -491,6 +496,7 @@ public void testVariancesOnCastedString()
.context(BaseCalciteQueryTest.QUERY_CONTEXT_DEFAULT)
.build()
),
ResultMatchMode.EQUALS_EPS,
ImmutableList.of(
NullHandling.replaceWithDefault()
? new Object[]{3.61497656362466, 3.960008417499471, 3.960008417499471, 15.681666666666667}
Expand Down Expand Up @@ -541,6 +547,7 @@ public void testEmptyTimeseriesResults()
.context(BaseCalciteQueryTest.QUERY_CONTEXT_DEFAULT)
.build()
),
ResultMatchMode.EQUALS_EPS,
ImmutableList.of(
NullHandling.replaceWithDefault()
? new Object[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}
Expand Down Expand Up @@ -621,6 +628,7 @@ public void testGroupByAggregatorDefaultValues()
.setContext(QUERY_CONTEXT_DEFAULT)
.build()
),
ResultMatchMode.EQUALS_EPS,
ImmutableList.of(
NullHandling.replaceWithDefault()
? new Object[]{"a", 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}
Expand Down Expand Up @@ -674,27 +682,8 @@ public void testVarianceAggAsInput()
.context(BaseCalciteQueryTest.QUERY_CONTEXT_DEFAULT)
.build()
),
ResultMatchMode.EQUALS_EPS,
expectedResults
);
}

@Override
public void assertResultsEquals(String sql, List<Object[]> expectedResults, List<Object[]> results)
{
Assert.assertEquals(expectedResults.size(), results.size());
for (int i = 0; i < expectedResults.size(); i++) {
Object[] expectedResult = expectedResults.get(i);
Object[] result = results.get(i);
Assert.assertEquals(expectedResult.length, result.length);
for (int j = 0; j < expectedResult.length; j++) {
if (expectedResult[j] instanceof Float) {
Assert.assertEquals((Float) expectedResult[j], (Float) result[j], 1e-5);
} else if (expectedResult[j] instanceof Double) {
Assert.assertEquals((Double) expectedResult[j], (Double) result[j], 1e-5);
} else {
Assert.assertEquals(expectedResult[j], result[j]);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
import com.google.inject.Inject;
import org.apache.druid.segment.column.ValueType;
import org.apache.druid.segment.data.Indexed;

import javax.annotation.Nullable;
Expand Down Expand Up @@ -161,6 +162,28 @@ public static <T> T defaultValueForClass(final Class<T> clazz)
}
}

/**
* Returns the default value for the given {@link ValueType}.
*
* May be null or non-null based on the current SQL-compatible null handling mode.
*/
@Nullable
@SuppressWarnings("unchecked")
public static Object defaultValueForType(ValueType type)
{
if (type == ValueType.FLOAT) {
return defaultFloatValue();
} else if (type == ValueType.DOUBLE) {
return defaultDoubleValue();
} else if (type == ValueType.LONG) {
return defaultLongValue();
} else if (type == ValueType.STRING) {
return defaultStringValue();
} else {
return null;
}
}

public static boolean isNullOrEquivalent(@Nullable String value)
{
return replaceWithDefault() ? Strings.isNullOrEmpty(value) : value == null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@
package org.apache.druid.common.config;

import org.apache.druid.java.util.common.StringUtils;
import org.apache.druid.segment.column.ValueType;
import org.apache.druid.segment.data.ListIndexed;
import org.apache.druid.testing.InitializedNullHandlingTest;
import org.junit.Assert;
import org.junit.Test;

import java.util.Collections;

import static org.apache.druid.common.config.NullHandling.defaultValueForClass;
import static org.apache.druid.common.config.NullHandling.defaultValueForType;
import static org.apache.druid.common.config.NullHandling.replaceWithDefault;
import static org.junit.Assert.assertEquals;

Expand Down Expand Up @@ -89,6 +92,17 @@ public void test_defaultValueForClass_object()
Assert.assertNull(NullHandling.defaultValueForClass(Object.class));
}

@Test
public void test_defaultValueForType()
{
assertEquals(defaultValueForClass(Float.class), defaultValueForType(ValueType.FLOAT));
assertEquals(defaultValueForClass(Double.class), defaultValueForType(ValueType.DOUBLE));
assertEquals(defaultValueForClass(Long.class), defaultValueForType(ValueType.LONG));
assertEquals(defaultValueForClass(String.class), defaultValueForType(ValueType.STRING));
assertEquals(defaultValueForClass(Object.class), defaultValueForType(ValueType.COMPLEX));
assertEquals(defaultValueForClass(Object.class), defaultValueForType(ValueType.ARRAY));
}

@Test
public void test_ignoreNullsStrings()
{
Expand Down
Loading
Loading