-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Changes from 35 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
bd55afd
fixes
kgyrtkirk 5cf1e2c
check for latest rewrite place
kgyrtkirk c4ff274
Revert "check for latest rewrite place"
kgyrtkirk 89844e9
some stuff
kgyrtkirk ed5d100
update test output
kgyrtkirk 2a4a3ab
updates to test ouptuts
kgyrtkirk 02aac9d
some stuff
kgyrtkirk a9877c4
move validator
kgyrtkirk f104ce4
cleanup
kgyrtkirk 145fe82
fix
kgyrtkirk 761cd68
change test slightly
kgyrtkirk a10fe7a
add apidoc cleanup warnings
kgyrtkirk 6082df5
cleanup/etc
kgyrtkirk 34a6aeb
instead of telling the story; add a fail with some reason whats the i…
kgyrtkirk 9b74ef5
Merge remote-tracking branch 'apache/master' into windowing-fix-test-cmp
kgyrtkirk e376ae9
lead-lag fix
kgyrtkirk 1acd53b
add test
kgyrtkirk a708ef2
remove unnecessary throw
kgyrtkirk 8fa0664
druidexception-trial
kgyrtkirk b484606
Revert "druidexception-trial"
kgyrtkirk 2858ff6
undo changes to no_grouping; add no_grouping2
kgyrtkirk 2e91d7c
Merge remote-tracking branch 'apache/master' into windowing-fix-test-cmp
kgyrtkirk 9a80c89
add missing assert on resultcount
kgyrtkirk ee2b35d
rename method; update
kgyrtkirk 4e216b7
introduce enum/etc
kgyrtkirk 5d0fcc0
make resultmatchmode accessible from TestBuilder#expectedResults
kgyrtkirk 0ddd3be
fix dump results to use log
kgyrtkirk 4073f5e
Merge remote-tracking branch 'apache/master' into windowing-fix-test-cmp
kgyrtkirk 47e81d8
Merge remote-tracking branch 'apache/master' into windowing-fix-test-cmp
kgyrtkirk edea152
fix
kgyrtkirk de099c6
handle null correctly
kgyrtkirk e018b2c
disable feature type based things for MSQ
kgyrtkirk a74a9fd
fix varianssqlaggtest
kgyrtkirk 185b8e7
use eps in other test
kgyrtkirk ed1bb89
fix intellij error
kgyrtkirk 91b1be9
add final
kgyrtkirk df73774
addrss review
kgyrtkirk 7714e2f
update test/string/etc
kgyrtkirk 78d1d31
write concat in 3 lines :D
kgyrtkirk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,6 +77,7 @@ | |
import org.apache.druid.segment.column.ColumnHolder; | ||
import org.apache.druid.segment.column.ColumnType; | ||
import org.apache.druid.segment.column.RowSignature; | ||
import org.apache.druid.segment.column.ValueType; | ||
import org.apache.druid.segment.join.JoinType; | ||
import org.apache.druid.segment.join.JoinableFactoryWrapper; | ||
import org.apache.druid.segment.virtual.ExpressionVirtualColumn; | ||
|
@@ -86,6 +87,7 @@ | |
import org.apache.druid.server.security.ForbiddenException; | ||
import org.apache.druid.server.security.ResourceAction; | ||
import org.apache.druid.sql.SqlStatementFactory; | ||
import org.apache.druid.sql.calcite.QueryTestRunner.QueryResults; | ||
import org.apache.druid.sql.calcite.expression.DruidExpression; | ||
import org.apache.druid.sql.calcite.planner.Calcites; | ||
import org.apache.druid.sql.calcite.planner.PlannerConfig; | ||
|
@@ -120,19 +122,24 @@ | |
import org.junit.rules.TemporaryFolder; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import java.io.IOException; | ||
import java.io.PrintStream; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.Properties; | ||
import java.util.Set; | ||
import java.util.function.Consumer; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* A base class for SQL query testing. It sets up query execution environment, provides useful helper methods, | ||
* and populates data using {@link CalciteTests#createMockWalker}. | ||
|
@@ -1033,11 +1040,13 @@ public ObjectMapper jsonMapper() | |
@Override | ||
public ResultsVerifier defaultResultsVerifier( | ||
List<Object[]> expectedResults, | ||
ResultMatchMode expectedResultMatchMode, | ||
RowSignature expectedResultSignature | ||
) | ||
{ | ||
return BaseCalciteQueryTest.this.defaultResultsVerifier( | ||
expectedResults, | ||
expectedResultMatchMode, | ||
expectedResultSignature | ||
); | ||
} | ||
|
@@ -1055,6 +1064,115 @@ public Map<String, Object> baseQueryContext() | |
} | ||
} | ||
|
||
public enum ResultMatchMode | ||
{ | ||
EQUALS { | ||
@Override | ||
void validate(int row, int column, ValueType type, Object expectedCell, Object resultCell) | ||
{ | ||
assertEquals( | ||
mismatchMessage(row, column), | ||
expectedCell, | ||
resultCell); | ||
} | ||
}, | ||
RELAX_NULLS { | ||
@Override | ||
void validate(int row, int column, ValueType type, Object expectedCell, Object resultCell) | ||
{ | ||
if (expectedCell == null) { | ||
if (resultCell == null) { | ||
return; | ||
} | ||
expectedCell = NullHandling.defaultValueForType(type); | ||
} | ||
EQUALS.validate(row, column, type, expectedCell, resultCell); | ||
} | ||
}, | ||
EQUALS_EPS { | ||
@Override | ||
void validate(int row, int column, ValueType type, Object expectedCell, Object resultCell) | ||
{ | ||
if (expectedCell instanceof Float) { | ||
assertEquals( | ||
mismatchMessage(row, column), | ||
(Float) expectedCell, | ||
(Float) resultCell, | ||
1e-5); | ||
} else if (expectedCell instanceof Double) { | ||
assertEquals( | ||
mismatchMessage(row, column), | ||
(Double) expectedCell, | ||
(Double) resultCell, | ||
1e-5); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
} else { | ||
EQUALS.validate(row, column, type, expectedCell, resultCell); | ||
} | ||
} | ||
}; | ||
|
||
abstract void validate(int row, int column, ValueType type, Object expectedCell, Object resultCell); | ||
|
||
private static String mismatchMessage(int row, int column) | ||
{ | ||
return String.format(Locale.ENGLISH, "column content mismatch at %d,%d", row, column); | ||
kgyrtkirk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
} | ||
|
||
/** | ||
* Validates the results with slight loosening in case {@link NullHandling} is not sql compatible. | ||
* | ||
* In case {@link NullHandling#replaceWithDefault()} is true, if the expected result is <code>null</code> it accepts | ||
* both <code>null</code> and the default value for that column as actual result. | ||
*/ | ||
public void assertResultsValid(ResultMatchMode matchMode, List<Object[]> expected, QueryResults queryResults) | ||
{ | ||
List<Object[]> results = queryResults.results; | ||
Assert.assertEquals("Result count mismatch", expected.size(), results.size()); | ||
|
||
final List<ValueType> types = new ArrayList<>(); | ||
|
||
boolean isMSQ = isMSQRowType(queryResults.signature); | ||
|
||
if (!isMSQ) { | ||
for (int i = 0; i < queryResults.signature.getColumnNames().size(); i++) { | ||
Optional<ColumnType> columnType = queryResults.signature.getColumnType(i); | ||
if (columnType.isPresent()) { | ||
types.add(columnType.get().getType()); | ||
} else { | ||
types.add(null); | ||
} | ||
} | ||
} | ||
|
||
int numRows = results.size(); | ||
for (int row = 0; row < numRows; row++) { | ||
Object[] expectedRow = expected.get(row); | ||
kgyrtkirk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Object[] resultRow = results.get(row); | ||
assertEquals("column count mismatch; at row#" + row, expectedRow.length, resultRow.length); | ||
|
||
for (int i = 0; i < resultRow.length; i++) { | ||
Object resultCell = resultRow[i]; | ||
Object expectedCell = expectedRow[i]; | ||
|
||
ResultMatchMode cellValidator = matchMode; | ||
cellValidator.validate( | ||
row, | ||
i, | ||
isMSQ ? null : types.get(i), | ||
expectedCell, | ||
resultCell); | ||
} | ||
} | ||
} | ||
|
||
private boolean isMSQRowType(RowSignature signature) | ||
{ | ||
List<String> colNames = signature.getColumnNames(); | ||
return colNames.size() == 1 && "TASK".equals(colNames.get(0)); | ||
} | ||
|
||
public void assertResultsEquals(String sql, List<Object[]> expectedResults, List<Object[]> results) | ||
{ | ||
int minSize = Math.min(results.size(), expectedResults.size()); | ||
|
@@ -1331,29 +1449,37 @@ default void verifyRowSignature(RowSignature rowSignature) | |
// do nothing | ||
} | ||
|
||
void verify(String sql, List<Object[]> results); | ||
void verify(String sql, QueryResults queryResults); | ||
} | ||
|
||
private ResultsVerifier defaultResultsVerifier( | ||
final List<Object[]> expectedResults, | ||
ResultMatchMode expectedResultMatchMode, | ||
final RowSignature expectedSignature | ||
) | ||
{ | ||
return new DefaultResultsVerifier(expectedResults, expectedSignature); | ||
return new DefaultResultsVerifier(expectedResults, expectedResultMatchMode, expectedSignature); | ||
} | ||
|
||
public class DefaultResultsVerifier implements ResultsVerifier | ||
{ | ||
protected final List<Object[]> expectedResults; | ||
@Nullable | ||
protected final RowSignature expectedResultRowSignature; | ||
protected final ResultMatchMode expectedResultMatchMode; | ||
|
||
public DefaultResultsVerifier(List<Object[]> expectedResults, RowSignature expectedSignature) | ||
public DefaultResultsVerifier(List<Object[]> expectedResults, ResultMatchMode expectedResultMatchMode, RowSignature expectedSignature) | ||
{ | ||
this.expectedResults = expectedResults; | ||
this.expectedResultMatchMode = expectedResultMatchMode; | ||
this.expectedResultRowSignature = expectedSignature; | ||
} | ||
|
||
public DefaultResultsVerifier(List<Object[]> expectedResults, RowSignature expectedSignature) | ||
{ | ||
this(expectedResults, ResultMatchMode.EQUALS, expectedSignature); | ||
} | ||
|
||
@Override | ||
public void verifyRowSignature(RowSignature rowSignature) | ||
{ | ||
|
@@ -1363,17 +1489,18 @@ public void verifyRowSignature(RowSignature rowSignature) | |
} | ||
|
||
@Override | ||
public void verify(String sql, List<Object[]> results) | ||
public void verify(String sql, QueryResults queryResults) | ||
{ | ||
try { | ||
Assert.assertEquals(StringUtils.format("result count: %s", sql), expectedResults.size(), results.size()); | ||
assertResultsEquals(sql, expectedResults, results); | ||
assertResultsValid(expectedResultMatchMode, expectedResults, queryResults); | ||
} | ||
catch (AssertionError e) { | ||
displayResults("Actual", results); | ||
System.out.println("sql: " + sql); | ||
displayResults("Actual", queryResults.results); | ||
throw e; | ||
} | ||
} | ||
|
||
} | ||
|
||
/** | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should make this a static variable and set it to 1e-5. Also is there any rationale behind chosing this value ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
two tests were overriding the
assertResultsEquals
method - and they had this constant in them; to set the absolute error bound to1e-5
I think they were making assertions on approximation results - which may be a little bit different based on the jvm or other external reasons.
I've extracted it into a constant