From 210a918f77785746a2ec3d6834076dd508cbd1bd Mon Sep 17 00:00:00 2001 From: Anton Gozhiy Date: Tue, 13 Aug 2019 22:08:03 +0300 Subject: [PATCH] Added an option for float / double precision that would help to solve precision related test failures (#594) --- .../original/maprdb/json/tpch_sf1_maprdb_json.json | 1 + .../sanity/maprdb/json/tpch_sf1_maprdb_json.json | 1 + .../org/apache/drill/test/framework/ColumnList.java | 12 ++++++++++-- .../apache/drill/test/framework/DrillTestJdbc.java | 4 ++-- .../apache/drill/test/framework/DrillTestOdbc.java | 2 +- .../apache/drill/test/framework/TestCaseModeler.java | 4 ++++ .../apache/drill/test/framework/TestVerifier.java | 12 +++++++----- 7 files changed, 26 insertions(+), 10 deletions(-) diff --git a/framework/resources/Advanced/tpch/tpch_sf1/original/maprdb/json/tpch_sf1_maprdb_json.json b/framework/resources/Advanced/tpch/tpch_sf1/original/maprdb/json/tpch_sf1_maprdb_json.json index 7230ef088..ff7a0ff3a 100755 --- a/framework/resources/Advanced/tpch/tpch_sf1/original/maprdb/json/tpch_sf1_maprdb_json.json +++ b/framework/resources/Advanced/tpch/tpch_sf1/original/maprdb/json/tpch_sf1_maprdb_json.json @@ -12,6 +12,7 @@ "schema": "mfs.tpch_sf1_maprdb_json", "output-format": "tsv", "expected-file": ".*.e_tsv", + "double-precision": 1.0E-11, "verification-type": [ "in-memory" ] diff --git a/framework/resources/Advanced/tpch/tpch_sf1/sanity/maprdb/json/tpch_sf1_maprdb_json.json b/framework/resources/Advanced/tpch/tpch_sf1/sanity/maprdb/json/tpch_sf1_maprdb_json.json index b5a007efd..ce72ec144 100755 --- a/framework/resources/Advanced/tpch/tpch_sf1/sanity/maprdb/json/tpch_sf1_maprdb_json.json +++ b/framework/resources/Advanced/tpch/tpch_sf1/sanity/maprdb/json/tpch_sf1_maprdb_json.json @@ -12,6 +12,7 @@ "schema": "mfs.tpch_sf1_maprdb_json", "output-format": "tsv", "expected-file": ".*.e_tsv", + "double-precision": 1.0E-11, "verification-type": [ "in-memory" ] diff --git a/framework/src/main/java/org/apache/drill/test/framework/ColumnList.java b/framework/src/main/java/org/apache/drill/test/framework/ColumnList.java index 4d24b5b0c..003644191 100644 --- a/framework/src/main/java/org/apache/drill/test/framework/ColumnList.java +++ b/framework/src/main/java/org/apache/drill/test/framework/ColumnList.java @@ -17,6 +17,8 @@ */ package org.apache.drill.test.framework; +import org.apache.drill.test.framework.TestCaseModeler.TestMatrix; + import java.math.BigDecimal; import java.sql.Types; import java.util.List; @@ -30,12 +32,18 @@ public class ColumnList { private final List values; private final List types; + private final TestMatrix matrix; private final boolean Simba; public static final String SIMBA_JDBC = "sjdbc"; public ColumnList(List types, List values) { + this(types, values, null); + } + + public ColumnList(List types, List values, TestMatrix matrix) { this.values = values; this.types = types; + this.matrix = matrix; if (TestDriver.cmdParam.driverExt != null && TestDriver.cmdParam.driverExt.equals(ColumnList.SIMBA_JDBC)) { this.Simba = true; @@ -155,7 +163,7 @@ private boolean compare(ColumnList o1, ColumnList o2) { float f1 = (Float) list1.get(i); float f2 = (Float) list2.get(i); if ((f1 + f2) / 2 != 0) { - if (!(Math.abs((f1 - f2) / ((f1 + f2) / 2)) < 1.0E-6)) return false; + return (Math.abs((f1 - f2) / ((f1 + f2) / 2)) < matrix.floatPrecision); } else if (f1 != 0) { return false; } @@ -168,7 +176,7 @@ private boolean compare(ColumnList o1, ColumnList o2) { // otherwise proceed with "loosened" logic if (!d1.equals(d2)) { if ((d1 + d2) / 2 != 0) { - if (!(Math.abs((d1 - d2) / ((d1 + d2) / 2)) < 1.0E-12)) return false; + return (Math.abs((d1 - d2) / ((d1 + d2) / 2)) < matrix.doublePrecision); } else if (d1 != 0) { return false; } diff --git a/framework/src/main/java/org/apache/drill/test/framework/DrillTestJdbc.java b/framework/src/main/java/org/apache/drill/test/framework/DrillTestJdbc.java index 8ee26edc0..18e310734 100644 --- a/framework/src/main/java/org/apache/drill/test/framework/DrillTestJdbc.java +++ b/framework/src/main/java/org/apache/drill/test/framework/DrillTestJdbc.java @@ -115,7 +115,7 @@ public void run() { executeQuery(query); if (getTestStatus()!= testStatus.CANCELED) { //Not to verify again if deliberately cancelled - testVerifier = new TestVerifier(columnTypes, query, columnLabels, matrix.verificationTypes); + testVerifier = new TestVerifier(columnTypes, query, columnLabels, matrix); if (query.startsWith("explain") || matrix.verificationTypes.get(0).equalsIgnoreCase("regex") || matrix.verificationTypes.get(0).equalsIgnoreCase("regex-no-order") || matrix.verificationTypes.get(0).equalsIgnoreCase("filter-ratio")) { @@ -253,7 +253,7 @@ private void executeQuery(String query) throws IOException, SQLException { if (resultSet != null) { while (resultSet.next()) { List values = Utils.getRowValues(resultSet); - ColumnList columnList = new ColumnList(columnTypes, values); + ColumnList columnList = new ColumnList(columnTypes, values, matrix); writer.write(columnList + "\n"); } } diff --git a/framework/src/main/java/org/apache/drill/test/framework/DrillTestOdbc.java b/framework/src/main/java/org/apache/drill/test/framework/DrillTestOdbc.java index c76a881c0..b1830e5d6 100644 --- a/framework/src/main/java/org/apache/drill/test/framework/DrillTestOdbc.java +++ b/framework/src/main/java/org/apache/drill/test/framework/DrillTestOdbc.java @@ -107,7 +107,7 @@ public void run() { switch (cmdConsOut.exitCode) { case 0: - TestVerifier testVerifier = new TestVerifier(columnTypes, query, columnLabels, matrix.verificationTypes); + TestVerifier testVerifier = new TestVerifier(columnTypes, query, columnLabels, matrix); try { if (query.startsWith("explain") || matrix.verificationTypes.get(0).equalsIgnoreCase("regex") || matrix.verificationTypes.get(0).equalsIgnoreCase("regex-no-order") || diff --git a/framework/src/main/java/org/apache/drill/test/framework/TestCaseModeler.java b/framework/src/main/java/org/apache/drill/test/framework/TestCaseModeler.java index 01c5ffc5a..978197589 100755 --- a/framework/src/main/java/org/apache/drill/test/framework/TestCaseModeler.java +++ b/framework/src/main/java/org/apache/drill/test/framework/TestCaseModeler.java @@ -91,6 +91,10 @@ public static class TestMatrix { // TODO: The below code can be reused when we decide to have username & password at suite level public String username = DrillTestDefaults.USERNAME; public String password = DrillTestDefaults.PASSWORD; + @JsonProperty("float-precision") + public double floatPrecision = 1.0E-6; + @JsonProperty("double-precision") + public double doublePrecision = 1.0E-12; @JsonProperty("verification-type") public List verificationTypes; diff --git a/framework/src/main/java/org/apache/drill/test/framework/TestVerifier.java b/framework/src/main/java/org/apache/drill/test/framework/TestVerifier.java index 089dd457f..57aedfbaf 100755 --- a/framework/src/main/java/org/apache/drill/test/framework/TestVerifier.java +++ b/framework/src/main/java/org/apache/drill/test/framework/TestVerifier.java @@ -41,6 +41,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.google.common.collect.Lists; +import org.apache.drill.test.framework.TestCaseModeler.TestMatrix; import org.apache.log4j.Logger; /** @@ -57,7 +58,7 @@ public class TestVerifier { private List types = null; private String query; private List columnLabels; - private List verificationTypes; + private TestMatrix matrix; private boolean checkType = true; public enum TestStatus { @@ -67,11 +68,11 @@ public enum TestStatus { public TestVerifier(List types, String query, List columnLabels, - List verificationType) { + TestMatrix matrix) { this.types = types; this.query = query; this.columnLabels = columnLabels; - this.verificationTypes = verificationType; + this.matrix = matrix; } public TestVerifier() { @@ -196,7 +197,7 @@ private Map loadFromFileToMap(String filename) * Detects the number of unexpected entries in the actual map * * @param count - * value of a particular entry in actual map + * value of a particular entry in actual map * @return unexpected count for that entry */ private int getUnexpectedCount(Map map, Map.Entry entry){ @@ -280,7 +281,7 @@ private Map loadFromFileToMap(String filename, boolean orde typedFields.add(fields[i]); } } - ColumnList cl = new ColumnList(types, typedFields); + ColumnList cl = new ColumnList(types, typedFields, matrix); if (ordered) { resultSet.add(cl); } else { @@ -699,6 +700,7 @@ public TestStatus verifyTextPlan(String expectedOutput, String actual = new String(Files.readAllBytes(Paths.get(actualOutput))); boolean verified = false; + List verificationTypes = matrix.verificationTypes; if (verificationTypes.get(0).equalsIgnoreCase("regex")) { verified = matchesAll(actual, expected); } else if (verificationTypes.get(0).equalsIgnoreCase("regex-no-order")) {