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

Changes to handle the double precision errors #532

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/1.e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.00000068987
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/1.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select cast(0.00000068989 as double);
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/10.e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.004
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/10.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select cast(0.004 as double);
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/11.e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.03000000001
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/11.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select cast(0.03 as float);
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/12.e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.3
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/12.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select cast(0.2 as float);
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/13.e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.788
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/13.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select cast(1.787 as float);
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/14.e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.78784
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/14.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select cast(1.7878 as double);
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/15.e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.7878788878
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/15.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select cast(1.7878787878 as double);
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/16.e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.78787 1.78788
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/16.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select cast(1.78787 as float),cast(1.78787 as float);
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/17.e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12.6767679
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/17.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select cast(12.676767 as float);
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/18.e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
134.67670001
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/18.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select cast(134.6767 as float);
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/19.e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1444.666
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/19.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select cast(1444.676 as float);
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/2.e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.000000688
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/2.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select cast(0.000000678 as double);
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/20.e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
15833.6767776
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/20.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select cast(15833.6767676 as double);
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/21.e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
233345.6766767
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/21.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select cast(233345.67676767 as double);
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/22.e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4523214.78
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/22.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select cast(4523214.76 as float);
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/23.e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1444.676677
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/23.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select cast(1444.676676 as float);
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/24.e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1444.676676677
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/24.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select cast(1444.676676676 as double);
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/25.e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
15833.67677
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/25.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select cast(15833.67676 as float);
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/26.e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
15833.676768
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/26.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select cast(15833.676767 as float);
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/27.e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
15833.6767677
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/27.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select cast(15833.6767676 as double);
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/28.e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
15833.67676768
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/28.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select cast(15833.67676767 as double);
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/29.e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
15833.676767668
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/29.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select cast(15833.676767667 as double);
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/3.e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0000006
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/3.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select cast(0.0000006 as double);
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/30.e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
15833.67676766768
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/30.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select cast(15833.67676766767 as double);
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/31.e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
233345.6767676768
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/31.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select cast(233345.6767676767 as double);
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/32.e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
233345.676767676768
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/32.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select cast(233345.676767676767 as double);
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/33.e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.67666767E8
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/33.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select cast(1.67676767E8 as double);
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/4.e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.00000589
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/4.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select cast(0.00000689 as double);
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/5.e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0001689
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/5.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select cast(0.0000689 as float);
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/6.e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.000009
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/6.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select cast(0.000006 as float);
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/7.e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.005
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/7.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select cast(0.00689 as float);
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/8.e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.00008
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/8.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select cast(0.00006 as float);
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/9.e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.00037
1 change: 1 addition & 0 deletions framework/resources/Functional/DataPrecision/9.q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select cast(0.0005 as float);
22 changes: 22 additions & 0 deletions framework/resources/Functional/DataPrecision/dataprecison.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"testId": "dataprecision",
"type": "group",
"description": "Test data precision queries via jdbc",
"submit-type": "jdbc",
"categories": [
"dataprecision"
],
"matrices": [
{
"query-file": ".*.q",
"schema": "dfs.root",
"output-format": "tsv",
"expected-file": ".*.e",
"verification-type": [
"in-memory"
]
}
],
"datasources": [
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ public class CmdParam {
@Parameter(names = {"-t"}, description = "timeout", required=false)
public int timeout = 120;

@Parameter(names = {"-pF"}, description = "precision value for float values", required=false)
public double precisionFloat = 1.0E-6;

@Parameter(names = {"-pD"}, description = "precision value for double values", required=false)
public double precisionDouble = 1.0E-7;

@Parameter(names = {"-w"}, description = "enable write actual query result to file", required=false)
public boolean outputQueryResult = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

import java.math.BigDecimal;
import java.sql.Types;
import java.util.List;
import java.util.*;


/**
* Class modeling a row in a ResultSet. It also stores a values of types of each
Expand All @@ -31,11 +32,14 @@ public class ColumnList {
private final List<Object> values;
private final List<Integer> types;
private final boolean Simba;
//array of every row when data precision errors
private final List <Integer> flags;
private int precisionErrorFlag;
public static final String SIMBA_JDBC = "sjdbc";

public ColumnList(List<Integer> types, List<Object> values) {
this.values = values;
this.types = types;
flags = new ArrayList<>(Collections.nCopies(values.size(), 0));
if (TestDriver.cmdParam.driverExt != null &&
TestDriver.cmdParam.driverExt.equals(ColumnList.SIMBA_JDBC)) {
this.Simba = true;
Expand Down Expand Up @@ -63,6 +67,11 @@ public List<Object> getValues() {
*/
@Override
public boolean equals(Object object) {
return (compare(this, (ColumnList) object)>0);
}


public int equallll(Object object) {
return compare(this, (ColumnList) object);
}

Expand Down Expand Up @@ -112,7 +121,10 @@ public String toString() {
values.set(i, s1);
}
}
sb.append(values.get(i) + "\t");
if(precisionErrorFlag == 1 && flags.get(i) == 1)
sb.append("\""+values.get(i)+"\"" + "\t");
else
sb.append(values.get(i) + "\t");
}
int type = (Integer) (types.get(values.size()-1));
if (Simba && (type == Types.VARCHAR)) {
Expand All @@ -128,24 +140,27 @@ public String toString() {
values.set(values.size()-1, s1);
}
}
sb.append(values.get(values.size() - 1));
return sb.toString();
if(precisionErrorFlag == 1 && flags.get(values.size() - 1) == 1)
sb.append("\""+values.get(values.size() - 1)+"\"");
else
sb.append(values.get(values.size() - 1));
return sb.toString();
}

private boolean compare(ColumnList o1, ColumnList o2) {
public int compare(ColumnList o1, ColumnList o2) {
List<Object> list1 = o1.values;
List<Object> list2 = o2.values;
if (list1.size() != list2.size()) return false;
if (list1.size() != list2.size()) return 0;
for (int i = 0; i < list1.size(); i++) {
if (types == null || types.size() == 0) {
if (!list1.get(i).equals(list2.get(i))) return false;
if (!list1.get(i).equals(list2.get(i))) return 0;
continue;
}
if (bothNull(list1.get(i), list2.get(i))) {
continue;
}
if (oneNull(list1.get(i), list2.get(i))) {
return false;
return 0;
}
int type = (Integer) (types.get(i));
try {
Expand All @@ -155,9 +170,21 @@ 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;
if (!(Math.abs((f1 - f2) / ((f1 + f2) / 2)) < TestDriver.cmdParam.precisionFloat)){
if (!(Math.abs((f1 - f2) / ((f1 + f2) / 2)) < TestDriver.cmdParam.precisionFloat*10)){
return 0;
}
else{
if(Math.abs(f1-f2)>0.01)
return 0;
precisionErrorFlag = 1;
flags.set(i,1);
return -1;
}
//return false;
}
} else if (f1 != 0) {
return false;
return 0;//data verification error
}
break;
case Types.DOUBLE:
Expand All @@ -168,26 +195,45 @@ 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;
if (!(Math.abs((d1 - d2) / ((d1 + d2) / 2)) < TestDriver.cmdParam.precisionDouble)){
if (!(Math.abs((d1 - d2) / ((d1 + d2) / 2)) < TestDriver.cmdParam.precisionDouble*10)){
if (!(Math.abs((d1 - d2) / ((d1 + d2) / 2)) < TestDriver.cmdParam.precisionDouble*100)){
return 0;
}
else{
if(Math.abs(d1-d2)>0.01)
return 0;
precisionErrorFlag = 1;
flags.set(i,1);
return -1;
}
}
else{
precisionErrorFlag = 1;
flags.set(i,1);
return -1;
}
//return false;
}
} else if (d1 != 0) {
return false;
return 0;
}
}
break;
case Types.DECIMAL:
BigDecimal bd1 = (BigDecimal) list1.get(i);
BigDecimal bd2 = (BigDecimal) list2.get(i);
if (!(bd1.compareTo(bd2) == 0)) return false;
if (!(bd1.compareTo(bd2) == 0)) return 0;
break;
default:
if (!(list1.get(i).equals(list2.get(i)))) return false;
if (!(list1.get(i).equals(list2.get(i)))) return 0;
break;
}
} catch (Exception e) {
if (!(list1.get(i).equals(list2.get(i)))) return false;
if (!(list1.get(i).equals(list2.get(i)))) return 0;
}
}
return true;
return 1;
}

public static boolean bothNull(Object obj1, Object obj2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.drill.test.framework.TestCaseModeler.TestMatrix;
import org.apache.drill.test.framework.TestVerifier.TestStatus;
import org.apache.drill.test.framework.TestVerifier.VerificationException;
import org.apache.drill.test.framework.TestVerifier.PrecisionException;
import org.apache.drill.test.framework.TestVerifier.PlanVerificationException;
import org.apache.log4j.Logger;

Expand Down Expand Up @@ -131,7 +132,10 @@ public void run() {
}
} catch (VerificationException e) {
fail(TestStatus.DATA_VERIFICATION_FAILURE, e);
} catch (PlanVerificationException e) {
}catch (PrecisionException e) {
fail(TestStatus.DATA_PRECISION_FAILURE, e);
}
catch (PlanVerificationException e) {
fail(TestStatus.PLAN_VERIFICATION_FAILURE, e);
} catch (Exception e) {
fail(TestStatus.EXECUTION_FAILURE, e);
Expand Down
Loading