OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
com.mapd.tests.DateTimeTest Class Reference
+ Collaboration diagram for com.mapd.tests.DateTimeTest:

Classes

enum  DateAddUnit
 
enum  DateDiffUnit
 
enum  DateExtractUnit
 
enum  DateTruncUnit
 
enum  Encoding
 
enum  Fuzzy
 

Static Public Member Functions

static LocalDateTime testDateTrunc (LocalDateTime d, DateTruncUnit f, HeavyDBTestClient client, Encoding enc) throws Exception
 
static LocalDateTime testDateTruncTable (LocalDateTime d, DateTruncUnit f, HeavyDBTestClient client, Encoding enc) throws Exception
 
static void testDateExtract (LocalDateTime d, DateExtractUnit f, HeavyDBTestClient client, Encoding enc) throws Exception
 
static void testDateExtractTable (LocalDateTime d, DateExtractUnit f, HeavyDBTestClient client, Encoding enc) throws Exception
 
static void testDiff (String fn, LocalDateTime d0, LocalDateTime d1, DateDiffUnit f, HeavyDBTestClient client, Encoding enc0, Encoding enc1) throws Exception
 
static void testDiffTable (String fn, LocalDateTime d0, LocalDateTime d1, DateDiffUnit f, HeavyDBTestClient client, Encoding enc0, Encoding enc1) throws Exception
 
static void testDateAdd (String fn, LocalDateTime d, DateAddUnit f, long units, HeavyDBTestClient client, Encoding enc) throws Exception
 
static void testDateAddTable (String fn, LocalDateTime d, DateAddUnit f, long units, HeavyDBTestClient client, Encoding enc) throws Exception
 
static void testAdd (LocalDateTime d, DateAddUnit f, long units, HeavyDBTestClient client, Encoding enc) throws Exception
 
static void testSub (LocalDateTime d, DateAddUnit f, long units, HeavyDBTestClient client, Encoding enc) throws Exception
 
static void createTestTable (HeavyDBTestClient client) throws Exception
 
static void main (String[] args) throws Exception
 

Static Package Functions

static LocalDateTime createRandomDateTime (Random r)
 
static LocalDateTime getDateTimeFromQuery (HeavyDBTestClient client, String sql) throws Exception
 
static long getLongFromQuery (HeavyDBTestClient client, String sql) throws Exception
 
 [static initializer]
 

Static Package Attributes

static EnumSet resultsToDump = EnumSet.of(Fuzzy.failed, Fuzzy.okish)
 
static EnumSet addAllowed = EnumSet.allOf(DateAddUnit.class)
 

Static Private Member Functions

static void updateValues (HeavyDBTestClient client, LocalDateTime a, Encoding aEnc) throws Exception
 
static void updateValues (HeavyDBTestClient client, LocalDateTime a, Encoding aEnc, LocalDateTime b, Encoding bEnc) throws Exception
 

Detailed Description

a (hopefully) complete test case for date/time functions in OmniSci.

Definition at line 21 of file DateTimeTest.java.

Member Function Documentation

com.mapd.tests.DateTimeTest.[static initializer] ( )
inlinestaticpackage
static LocalDateTime com.mapd.tests.DateTimeTest.createRandomDateTime ( Random  r)
inlinestaticpackage

Definition at line 555 of file DateTimeTest.java.

Referenced by com.mapd.tests.DateTimeTest.main().

555  {
556  try {
557  int year = 1900 + r.nextInt(200);
558  int month = 1 + r.nextInt(12);
559  int dayOfMonth = 1 + r.nextInt(31);
560  int hour = r.nextInt(24);
561  int minute = r.nextInt(60);
562  int second = r.nextInt(60);
563  int nanoOfSecond = r.nextInt(1000 * 1000 * 1000);
564 
565  return LocalDateTime.of(
566  year, month, dayOfMonth, hour, minute, second, nanoOfSecond);
567  } catch (Exception e) {
568  return createRandomDateTime(r);
569  }
570  }
static LocalDateTime createRandomDateTime(Random r)

+ Here is the caller graph for this function:

static void com.mapd.tests.DateTimeTest.createTestTable ( HeavyDBTestClient  client) throws Exception
inlinestatic

Definition at line 1052 of file DateTimeTest.java.

Referenced by com.mapd.tests.DateTimeTest.main().

1052  {
1053  client.runSql("DROP TABLE IF EXISTS DateTimeTest;");
1054  String sqlCreate = "CREATE TABLE DateTimeTest(id int";
1055  String sqlInsert = "INSERT INTO DateTimeTest VALUES(0";
1056  for (Encoding e : Encoding.values()) {
1057  sqlCreate += ", " + e.toSqlColumn("a", null) + " " + e.sqlType;
1058  sqlCreate += ", " + e.toSqlColumn("b", null) + " " + e.sqlType;
1059  sqlInsert += ", null, null";
1060  }
1061 
1062  sqlCreate += ");";
1063  sqlInsert += ");";
1064 
1065  client.runSql(sqlCreate);
1066  client.runSql(sqlInsert);
1067 
1068  System.out.println("CREATE: " + sqlCreate);
1069  System.out.println("INSERT: " + sqlInsert);
1070  }

+ Here is the caller graph for this function:

static LocalDateTime com.mapd.tests.DateTimeTest.getDateTimeFromQuery ( HeavyDBTestClient  client,
String  sql 
) throws Exception
inlinestaticpackage

Definition at line 672 of file DateTimeTest.java.

References MIN, and run_benchmark_import.res.

Referenced by com.mapd.tests.DateTimeTest.testAdd(), com.mapd.tests.DateTimeTest.testDateAdd(), com.mapd.tests.DateTimeTest.testDateAddTable(), com.mapd.tests.DateTimeTest.testDateTrunc(), com.mapd.tests.DateTimeTest.testDateTruncTable(), and com.mapd.tests.DateTimeTest.testSub().

673  {
674  try {
675  ai.heavy.thrift.server.TQueryResult res = client.runSql(sql);
676  LocalDateTime r = null;
677  if (res.row_set.is_columnar) {
678  TTypeInfo tt = res.row_set.row_desc.get(0).col_type;
679  int pow = (int) Math.pow(10, tt.precision);
680  long val = res.row_set.columns.get(0).data.int_col.get(0);
681  int nanosPow = (int) Math.pow(10, 9 - tt.precision);
682  long nanos = (val % pow);
683  if (nanos < 0) {
684  nanos = pow + nanos;
685  }
686  nanos *= nanosPow;
687  r = LocalDateTime.ofEpochSecond(
688  Math.floorDiv(val, pow), (int) nanos, ZoneOffset.UTC);
689 
690  } else {
691  throw new RuntimeException("Unsupported!");
692  }
693 
694  return r;
695  } catch (TDBException e) {
696  System.out.println("Query failed: " + sql + " -- " + e.getError_msg());
697  return LocalDateTime.MIN;
698 
699  } catch (Exception e) {
700  System.out.println("Query failed: " + sql + " -- " + e.getMessage());
701  return LocalDateTime.MIN;
702  }
703  }

+ Here is the caller graph for this function:

static long com.mapd.tests.DateTimeTest.getLongFromQuery ( HeavyDBTestClient  client,
String  sql 
) throws Exception
inlinestaticpackage

Definition at line 705 of file DateTimeTest.java.

References run_benchmark_import.res.

Referenced by com.mapd.tests.DateTimeTest.testDateExtract(), com.mapd.tests.DateTimeTest.testDateExtractTable(), com.mapd.tests.DateTimeTest.testDiff(), and com.mapd.tests.DateTimeTest.testDiffTable().

705  {
706  try {
707  ai.heavy.thrift.server.TQueryResult res = client.runSql(sql);
708  long r = -1;
709  if (res.row_set.is_columnar) {
710  long val = res.row_set.columns.get(0).data.int_col.get(0);
711  r = val;
712  } else {
713  throw new RuntimeException("Unsupported!");
714  }
715  return r;
716  } catch (TDBException e) {
717  System.out.println("Query failed: " + sql + " -- " + e.getError_msg());
718  return Long.MIN_VALUE;
719  } catch (Exception e) {
720  System.out.println("Query failed: " + sql + " -- " + e.getMessage());
721  return Long.MIN_VALUE;
722  }
723  }

+ Here is the caller graph for this function:

static void com.mapd.tests.DateTimeTest.main ( String[]  args) throws Exception
inlinestatic

Definition at line 1072 of file DateTimeTest.java.

References run_benchmark_import.args, com.mapd.tests.DateTimeTest.createRandomDateTime(), com.mapd.tests.DateTimeTest.createTestTable(), f(), com.mapd.tests.DateTimeTest.Fuzzy.failed, com.mapd.tests.DateTimeTest.Fuzzy.okish, com.mapd.tests.DateTimeTest.resultsToDump, com.mapd.tests.DateTimeTest.testAdd(), com.mapd.tests.DateTimeTest.testDateAdd(), com.mapd.tests.DateTimeTest.testDateExtract(), com.mapd.tests.DateTimeTest.testDateTrunc(), com.mapd.tests.DateTimeTest.testDiff(), and com.mapd.tests.DateTimeTest.testSub().

1072  {
1073  long seed;
1074 
1075  // to reproduce a previous run, use the same seed
1076  if (0 < args.length) {
1077  seed = Long.parseLong(args[0], 10);
1078  } else {
1079  seed = System.currentTimeMillis();
1080  }
1081 
1082  System.out.println("Seed: " + seed);
1083  Random r = new Random(seed);
1084 
1085  HeavyDBTestClient su = HeavyDBTestClient.getClient(
1086  "localhost", 6274, "heavyai", "admin", "HyperInteractive");
1087  LocalDateTime d0 = createRandomDateTime(r);
1088  LocalDateTime d1 = createRandomDateTime(r);
1089 
1090  createTestTable(su);
1091 
1092  // don't dump OK results
1093  resultsToDump = EnumSet.of(Fuzzy.failed, Fuzzy.okish);
1094  boolean testTrunc = true;
1095  boolean testExtract = true;
1096  boolean testDiff = true;
1097  boolean testAdd = true;
1098 
1099  if (testTrunc) {
1100  for (Encoding enc0 : Encoding.values()) {
1101  for (DateTruncUnit f : DateTruncUnit.values()) {
1102  LocalDateTime e = testDateTrunc(d0, f, su, enc0);
1103  e = e.minus(1, ChronoUnit.NANOS);
1104  testDateTrunc(e, f, su, enc0);
1105  e = testDateTrunc(d1, f, su, enc0);
1106  e = e.minus(1, ChronoUnit.NANOS);
1107  testDateTrunc(e, f, su, enc0);
1108  }
1109  }
1110  }
1111 
1112  if (testExtract) {
1113  for (Encoding enc0 : Encoding.values()) {
1114  for (DateExtractUnit f : DateExtractUnit.values()) {
1115  testDateExtract(d0, f, su, enc0);
1116  testDateExtract(d0.minusNanos(1), f, su, enc0);
1117  testDateExtract(d0.plusNanos(1), f, su, enc0);
1118  testDateExtract(d1, f, su, enc0);
1119  testDateExtract(d1.minusNanos(1), f, su, enc0);
1120  testDateExtract(d1.plusNanos(1), f, su, enc0);
1121  }
1122  }
1123  }
1124 
1125  if (testDiff) {
1126  for (Encoding enc0 : Encoding.values()) {
1127  for (Encoding enc1 : Encoding.values()) {
1128  for (DateDiffUnit f : DateDiffUnit.values()) {
1129  for (String fn : Arrays.asList("TIMESTAMPDIFF" /* , "DATEDIFF" */)) {
1130  testDiff(fn, d0, d1, f, su, enc0, enc1);
1131  testDiff(fn, d1, d0, f, su, enc0, enc1);
1132  testDiff(fn, d0, d0, f, su, enc0, enc1);
1133  testDiff(fn, d1, d1, f, su, enc0, enc1);
1134  }
1135  }
1136  }
1137  }
1138  }
1139 
1140  if (testAdd) {
1141  for (DateAddUnit f : DateAddUnit.values()) {
1142  long units = r.nextLong() % f.max;
1143  if (r.nextBoolean()) {
1144  units *= -1L;
1145  }
1146  for (Encoding enc0 : Encoding.values()) {
1147  for (String fn : Arrays.asList("TIMESTAMPADD", "DATEADD")) {
1148  testDateAdd(fn, d0, f, units, su, enc0);
1149  testDateAdd(fn, d1, f, units, su, enc0);
1150  }
1151  testAdd(d0, f, units, su, enc0);
1152  testSub(d0, f, units, su, enc0);
1153  testAdd(d1, f, units, su, enc0);
1154  testSub(d1, f, units, su, enc0);
1155  }
1156  }
1157  }
1158  }
static LocalDateTime createRandomDateTime(Random r)
static void testDateAdd(String fn, LocalDateTime d, DateAddUnit f, long units, HeavyDBTestClient client, Encoding enc)
static void testDiff(String fn, LocalDateTime d0, LocalDateTime d1, DateDiffUnit f, HeavyDBTestClient client, Encoding enc0, Encoding enc1)
static void createTestTable(HeavyDBTestClient client)
static void testDateExtract(LocalDateTime d, DateExtractUnit f, HeavyDBTestClient client, Encoding enc)
torch::Tensor f(torch::Tensor x, torch::Tensor W_target, torch::Tensor b_target)
static void testSub(LocalDateTime d, DateAddUnit f, long units, HeavyDBTestClient client, Encoding enc)
static void testAdd(LocalDateTime d, DateAddUnit f, long units, HeavyDBTestClient client, Encoding enc)
static LocalDateTime testDateTrunc(LocalDateTime d, DateTruncUnit f, HeavyDBTestClient client, Encoding enc)

+ Here is the call graph for this function:

static void com.mapd.tests.DateTimeTest.testAdd ( LocalDateTime  d,
DateAddUnit  f,
long  units,
HeavyDBTestClient  client,
Encoding  enc 
) throws Exception
inlinestatic

Definition at line 941 of file DateTimeTest.java.

References com.mapd.tests.DateTimeTest.addAllowed, f(), com.mapd.tests.DateTimeTest.getDateTimeFromQuery(), and com.mapd.tests.DateTimeTest.resultsToDump.

Referenced by com.mapd.tests.DateTimeTest.main().

945  {
946  if (!addAllowed.contains(f)) {
947  return;
948  }
949 
950  String sql =
951  "SELECT " + enc.toSql(d) + " + INTERVAL '" + units + "' " + f.sqlToken + " ;";
952  LocalDateTime r = getDateTimeFromQuery(client, sql);
953 
954  LocalDateTime expected = f.add.apply(Pair.create(enc.clear(d), units));
955  expected = enc.clearForDateAddResult(expected);
956 
957  Fuzzy rc = Fuzzy.compareDateAdd(expected, r, enc);
958  if (resultsToDump.contains(rc)) {
959  System.out.println("Query " + rc + ": " + sql
960  + " -> expected: " + expected.toString() + " got " + r.toString());
961  }
962  }
static LocalDateTime getDateTimeFromQuery(HeavyDBTestClient client, String sql)
torch::Tensor f(torch::Tensor x, torch::Tensor W_target, torch::Tensor b_target)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void com.mapd.tests.DateTimeTest.testDateAdd ( String  fn,
LocalDateTime  d,
DateAddUnit  f,
long  units,
HeavyDBTestClient  client,
Encoding  enc 
) throws Exception
inlinestatic

Definition at line 882 of file DateTimeTest.java.

References f(), com.mapd.tests.DateTimeTest.getDateTimeFromQuery(), com.mapd.tests.DateTimeTest.resultsToDump, and com.mapd.tests.DateTimeTest.testDateAddTable().

Referenced by com.mapd.tests.DateTimeTest.main().

887  {
888  String sql =
889  "SELECT " + fn + "(" + f.sqlToken + ", " + units + ", " + enc.toSql(d) + ");";
890  LocalDateTime r = getDateTimeFromQuery(client, sql);
891 
892  LocalDateTime expected = f.add.apply(Pair.create(enc.clear(d), units));
893  expected = enc.clearForDateAddResult(expected);
894 
895  Fuzzy rc = Fuzzy.compareDateAdd(expected, r, enc);
896  if (resultsToDump.contains(rc)) {
897  System.out.println("Query " + rc + ": " + sql
898  + " -> expected: " + expected.toString() + " got " + r.toString());
899  }
900 
901  testDateAddTable(fn, d, f, units, client, enc);
902  }
static LocalDateTime getDateTimeFromQuery(HeavyDBTestClient client, String sql)
static void testDateAddTable(String fn, LocalDateTime d, DateAddUnit f, long units, HeavyDBTestClient client, Encoding enc)
torch::Tensor f(torch::Tensor x, torch::Tensor W_target, torch::Tensor b_target)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void com.mapd.tests.DateTimeTest.testDateAddTable ( String  fn,
LocalDateTime  d,
DateAddUnit  f,
long  units,
HeavyDBTestClient  client,
Encoding  enc 
) throws Exception
inlinestatic

Definition at line 904 of file DateTimeTest.java.

References com.mapd.tests.DateTimeTest.getDateTimeFromQuery(), com.mapd.tests.DateTimeTest.resultsToDump, and com.mapd.tests.DateTimeTest.updateValues().

Referenced by com.mapd.tests.DateTimeTest.testDateAdd().

909  {
910  if (!enc.isValid(d)) {
911  return;
912  }
913 
914  updateValues(client, d, enc);
915  String sql = "SELECT " + fn + "(" + f.sqlToken + ", " + units + ", "
916  + enc.toSqlColumn("a", d) + ") FROM DateTimeTest;";
917  LocalDateTime r = getDateTimeFromQuery(client, sql);
918 
919  LocalDateTime expected = f.add.apply(Pair.create(enc.clear(d), units));
920  expected = enc.clearForDateAddResult(expected);
921 
922  Fuzzy rc = Fuzzy.compareDateAdd(expected, r, enc);
923  if (resultsToDump.contains(rc)) {
924  System.out.println("Query " + rc + ": " + sql
925  + " -> expected: " + expected.toString() + " got " + r.toString());
926  }
927  }
static LocalDateTime getDateTimeFromQuery(HeavyDBTestClient client, String sql)
static void updateValues(HeavyDBTestClient client, LocalDateTime a, Encoding aEnc)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void com.mapd.tests.DateTimeTest.testDateExtract ( LocalDateTime  d,
DateExtractUnit  f,
HeavyDBTestClient  client,
Encoding  enc 
) throws Exception
inlinestatic

Definition at line 791 of file DateTimeTest.java.

References f(), com.mapd.tests.DateTimeTest.getLongFromQuery(), com.mapd.tests.DateTimeTest.resultsToDump, and com.mapd.tests.DateTimeTest.testDateExtractTable().

Referenced by com.mapd.tests.DateTimeTest.main().

793  {
794  String sql = "SELECT EXTRACT(" + f.sqlToken + " FROM " + enc.toSql(d) + ");";
795  long r = getLongFromQuery(client, sql);
796 
797  d = enc.clear(d);
798  long expected = f.extract.apply(d);
799 
800  Fuzzy rc = Fuzzy.compare(expected, r);
801  if (resultsToDump.contains(rc)) {
802  System.out.println(
803  "Query " + rc + ": " + sql + " -> expected: " + expected + " got " + r);
804  }
805 
806  testDateExtractTable(d, f, client, enc);
807  }
torch::Tensor f(torch::Tensor x, torch::Tensor W_target, torch::Tensor b_target)
static long getLongFromQuery(HeavyDBTestClient client, String sql)
static void testDateExtractTable(LocalDateTime d, DateExtractUnit f, HeavyDBTestClient client, Encoding enc)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void com.mapd.tests.DateTimeTest.testDateExtractTable ( LocalDateTime  d,
DateExtractUnit  f,
HeavyDBTestClient  client,
Encoding  enc 
) throws Exception
inlinestatic

Definition at line 809 of file DateTimeTest.java.

References com.mapd.tests.DateTimeTest.getLongFromQuery(), com.mapd.tests.DateTimeTest.resultsToDump, and com.mapd.tests.DateTimeTest.updateValues().

Referenced by com.mapd.tests.DateTimeTest.testDateExtract().

811  {
812  if (!enc.isValid(d)) {
813  return;
814  }
815 
816  updateValues(client, d, enc);
817  String sql = "SELECT EXTRACT(" + f.sqlToken + " FROM " + enc.toSqlColumn("a", d)
818  + ") FROM DateTimeTest;";
819  long r = getLongFromQuery(client, sql);
820 
821  d = enc.clear(d);
822  long expected = f.extract.apply(d);
823 
824  Fuzzy rc = Fuzzy.compare(expected, r);
825  if (resultsToDump.contains(rc)) {
826  System.out.println(
827  "Query " + rc + ": " + sql + " -> expected: " + expected + " got " + r);
828  }
829  }
static void updateValues(HeavyDBTestClient client, LocalDateTime a, Encoding aEnc)
static long getLongFromQuery(HeavyDBTestClient client, String sql)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static LocalDateTime com.mapd.tests.DateTimeTest.testDateTrunc ( LocalDateTime  d,
DateTruncUnit  f,
HeavyDBTestClient  client,
Encoding  enc 
) throws Exception
inlinestatic

Definition at line 725 of file DateTimeTest.java.

References f(), com.mapd.tests.DateTimeTest.getDateTimeFromQuery(), com.mapd.tests.DateTimeTest.resultsToDump, and com.mapd.tests.DateTimeTest.testDateTruncTable().

Referenced by com.mapd.tests.DateTimeTest.main().

727  {
728  if (!enc.isValid(d)) {
729  return d;
730  }
731 
732  String sql = "SELECT DATE_TRUNC('" + f.sqlToken + "', " + enc.toSql(d) + ");";
733  LocalDateTime r = getDateTimeFromQuery(client, sql);
734  LocalDateTime expected = f.trunc.apply(d);
735  expected = enc.clear(expected);
736 
737  Fuzzy rc = Fuzzy.compare(expected, r, enc);
738  if (resultsToDump.contains(rc)) {
739  System.out.println("Query " + rc + ": " + sql
740  + " -> expected: " + expected.toString() + " got " + r.toString());
741  }
742 
743  return testDateTruncTable(d, f, client, enc);
744  }
static LocalDateTime getDateTimeFromQuery(HeavyDBTestClient client, String sql)
static LocalDateTime testDateTruncTable(LocalDateTime d, DateTruncUnit f, HeavyDBTestClient client, Encoding enc)
torch::Tensor f(torch::Tensor x, torch::Tensor W_target, torch::Tensor b_target)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static LocalDateTime com.mapd.tests.DateTimeTest.testDateTruncTable ( LocalDateTime  d,
DateTruncUnit  f,
HeavyDBTestClient  client,
Encoding  enc 
) throws Exception
inlinestatic

Definition at line 772 of file DateTimeTest.java.

References com.mapd.tests.DateTimeTest.getDateTimeFromQuery(), com.mapd.tests.DateTimeTest.resultsToDump, and com.mapd.tests.DateTimeTest.updateValues().

Referenced by com.mapd.tests.DateTimeTest.testDateTrunc().

774  {
775  updateValues(client, d, enc);
776  String sql = "SELECT DATE_TRUNC('" + f.sqlToken + "', " + enc.toSqlColumn("a", d)
777  + ") FROM DateTimeTest;";
778  LocalDateTime r = getDateTimeFromQuery(client, sql);
779  LocalDateTime expected = f.trunc.apply(d);
780  expected = enc.clear(expected);
781 
782  Fuzzy rc = Fuzzy.compare(expected, r, enc);
783  if (resultsToDump.contains(rc)) {
784  System.out.println("Query " + rc + ": " + sql
785  + " -> expected: " + expected.toString() + " got " + r.toString());
786  }
787 
788  return expected;
789  }
static LocalDateTime getDateTimeFromQuery(HeavyDBTestClient client, String sql)
static void updateValues(HeavyDBTestClient client, LocalDateTime a, Encoding aEnc)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void com.mapd.tests.DateTimeTest.testDiff ( String  fn,
LocalDateTime  d0,
LocalDateTime  d1,
DateDiffUnit  f,
HeavyDBTestClient  client,
Encoding  enc0,
Encoding  enc1 
) throws Exception
inlinestatic

Definition at line 831 of file DateTimeTest.java.

References f(), com.mapd.tests.DateTimeTest.getLongFromQuery(), com.mapd.tests.DateTimeTest.resultsToDump, and com.mapd.tests.DateTimeTest.testDiffTable().

Referenced by com.mapd.tests.DateTimeTest.main().

837  {
838  String sql = "SELECT " + fn + "(" + f.sqlToken + ", " + enc0.toSql(d0) + ", "
839  + enc1.toSql(d1) + ");";
840  long r = getLongFromQuery(client, sql);
841  d0 = enc0.clear(d0);
842  d1 = enc1.clear(d1);
843 
844  long expected = f.diff.apply(Pair.create(d0, d1));
845 
846  Fuzzy rc = Fuzzy.compare(expected, r);
847  if (resultsToDump.contains(rc)) {
848  System.out.println(
849  "Query " + rc + ": " + sql + " -> expected: " + expected + " got " + r);
850  }
851 
852  testDiffTable(fn, d0, d1, f, client, enc0, enc1);
853  }
torch::Tensor f(torch::Tensor x, torch::Tensor W_target, torch::Tensor b_target)
static long getLongFromQuery(HeavyDBTestClient client, String sql)
static void testDiffTable(String fn, LocalDateTime d0, LocalDateTime d1, DateDiffUnit f, HeavyDBTestClient client, Encoding enc0, Encoding enc1)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void com.mapd.tests.DateTimeTest.testDiffTable ( String  fn,
LocalDateTime  d0,
LocalDateTime  d1,
DateDiffUnit  f,
HeavyDBTestClient  client,
Encoding  enc0,
Encoding  enc1 
) throws Exception
inlinestatic

Definition at line 855 of file DateTimeTest.java.

References com.mapd.tests.DateTimeTest.getLongFromQuery(), com.mapd.tests.DateTimeTest.resultsToDump, and com.mapd.tests.DateTimeTest.updateValues().

Referenced by com.mapd.tests.DateTimeTest.testDiff().

861  {
862  if (!enc0.isValid(d0) || !enc1.isValid(d1)) {
863  return;
864  }
865 
866  updateValues(client, d0, enc0, d1, enc1);
867  String sql = "SELECT " + fn + "(" + f.sqlToken + ", " + enc0.toSqlColumn("a", d0)
868  + ", " + enc1.toSqlColumn("b", d1) + ") FROM DateTimeTest;";
869  long r = getLongFromQuery(client, sql);
870  d0 = enc0.clear(d0);
871  d1 = enc1.clear(d1);
872 
873  long expected = f.diff.apply(Pair.create(d0, d1));
874 
875  Fuzzy rc = Fuzzy.compare(expected, r);
876  if (resultsToDump.contains(rc)) {
877  System.out.println(
878  "Query " + rc + ": " + sql + " -> expected: " + expected + " got " + r);
879  }
880  }
static void updateValues(HeavyDBTestClient client, LocalDateTime a, Encoding aEnc)
static long getLongFromQuery(HeavyDBTestClient client, String sql)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void com.mapd.tests.DateTimeTest.testSub ( LocalDateTime  d,
DateAddUnit  f,
long  units,
HeavyDBTestClient  client,
Encoding  enc 
) throws Exception
inlinestatic

Definition at line 964 of file DateTimeTest.java.

References com.mapd.tests.DateTimeTest.addAllowed, f(), com.mapd.tests.DateTimeTest.getDateTimeFromQuery(), and com.mapd.tests.DateTimeTest.resultsToDump.

Referenced by com.mapd.tests.DateTimeTest.main().

968  {
969  if (!addAllowed.contains(f)) {
970  return;
971  }
972 
973  long toSub = -units;
974 
975  String sql =
976  "SELECT " + enc.toSql(d) + " - INTERVAL '" + toSub + "' " + f.sqlToken + " ;";
977  LocalDateTime r = getDateTimeFromQuery(client, sql);
978 
979  LocalDateTime expected = f.add.apply(Pair.create(enc.clear(d), units));
980  expected = enc.clearForDateAddResult(expected);
981 
982  Fuzzy rc = Fuzzy.compareDateAdd(expected, r, enc);
983  if (resultsToDump.contains(rc)) {
984  System.out.println("Query " + rc + ": " + sql
985  + " -> expected: " + expected.toString() + " got " + r.toString());
986  }
987  }
static LocalDateTime getDateTimeFromQuery(HeavyDBTestClient client, String sql)
torch::Tensor f(torch::Tensor x, torch::Tensor W_target, torch::Tensor b_target)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void com.mapd.tests.DateTimeTest.updateValues ( HeavyDBTestClient  client,
LocalDateTime  a,
Encoding  aEnc 
) throws Exception
inlinestaticprivate

Definition at line 746 of file DateTimeTest.java.

References anonymous_namespace{Utm.h}.a.

Referenced by com.mapd.tests.DateTimeTest.testDateAddTable(), com.mapd.tests.DateTimeTest.testDateExtractTable(), com.mapd.tests.DateTimeTest.testDateTruncTable(), and com.mapd.tests.DateTimeTest.testDiffTable().

747  {
748  updateValues(client, a, aEnc, null, null);
749  }
constexpr double a
Definition: Utm.h:32
static void updateValues(HeavyDBTestClient client, LocalDateTime a, Encoding aEnc)

+ Here is the caller graph for this function:

static void com.mapd.tests.DateTimeTest.updateValues ( HeavyDBTestClient  client,
LocalDateTime  a,
Encoding  aEnc,
LocalDateTime  b,
Encoding  bEnc 
) throws Exception
inlinestaticprivate

Definition at line 751 of file DateTimeTest.java.

References anonymous_namespace{Utm.h}.a.

755  {
756  String sqlUpdate = "UPDATE DateTimeTest set " + aEnc.toSqlColumn("a", null) + " = "
757  + aEnc.toSql(a);
758 
759  if (null != b) {
760  sqlUpdate += ", " + bEnc.toSqlColumn("b", null) + " = " + bEnc.toSql(b);
761  }
762 
763  sqlUpdate += ";";
764 
765  try {
766  client.runSql(sqlUpdate);
767  } catch (TDBException e) {
768  System.out.println("Update failed: " + sqlUpdate + " " + e.getError_msg());
769  }
770  }
constexpr double a
Definition: Utm.h:32

Member Data Documentation

EnumSet com.mapd.tests.DateTimeTest.addAllowed = EnumSet.allOf(DateAddUnit.class)
staticpackage

The documentation for this class was generated from the following file: