OmniSciDB  95562058bd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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, MapdTestClient client, Encoding enc) throws Exception
 
static LocalDateTime testDateTruncTable (LocalDateTime d, DateTruncUnit f, MapdTestClient client, Encoding enc) throws Exception
 
static void testDateExtract (LocalDateTime d, DateExtractUnit f, MapdTestClient client, Encoding enc) throws Exception
 
static void testDateExtractTable (LocalDateTime d, DateExtractUnit f, MapdTestClient client, Encoding enc) throws Exception
 
static void testDiff (String fn, LocalDateTime d0, LocalDateTime d1, DateDiffUnit f, MapdTestClient client, Encoding enc0, Encoding enc1) throws Exception
 
static void testDiffTable (String fn, LocalDateTime d0, LocalDateTime d1, DateDiffUnit f, MapdTestClient client, Encoding enc0, Encoding enc1) throws Exception
 
static void testDateAdd (String fn, LocalDateTime d, DateAddUnit f, long units, MapdTestClient client, Encoding enc) throws Exception
 
static void testDateAddTable (String fn, LocalDateTime d, DateAddUnit f, long units, MapdTestClient client, Encoding enc) throws Exception
 
static void testAdd (LocalDateTime d, DateAddUnit f, long units, MapdTestClient client, Encoding enc) throws Exception
 
static void testSub (LocalDateTime d, DateAddUnit f, long units, MapdTestClient client, Encoding enc) throws Exception
 
static void createTestTable (MapdTestClient client) throws Exception
 
static void main (String[] args) throws Exception
 

Static Package Functions

static LocalDateTime createRandomDateTime (Random r)
 
static LocalDateTime getDateTimeFromQuery (MapdTestClient client, String sql) throws Exception
 
static long getLongFromQuery (MapdTestClient 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 (MapdTestClient client, LocalDateTime a, Encoding aEnc) throws Exception
 
static void updateValues (MapdTestClient 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 ( MapdTestClient  client) throws Exception
inlinestatic

Definition at line 1048 of file DateTimeTest.java.

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

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

+ Here is the caller graph for this function:

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

Definition at line 672 of file DateTimeTest.java.

References 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  com.omnisci.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 (TOmniSciException e) {
696  System.out.println("Query failed: " + sql + " -- " + e.error_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 ( MapdTestClient  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  com.omnisci.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 (TOmniSciException e) {
717  System.out.println("Query failed: " + sql + " -- " + e.error_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 1068 of file DateTimeTest.java.

References run_benchmark_import.args, com.mapd.tests.DateTimeTest.createRandomDateTime(), com.mapd.tests.DateTimeTest.createTestTable(), 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().

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

+ Here is the call graph for this function:

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

Definition at line 941 of file DateTimeTest.java.

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

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

943  {
944  if (!addAllowed.contains(f)) {
945  return;
946  }
947 
948  String sql =
949  "SELECT " + enc.toSql(d) + " + INTERVAL '" + units + "' " + f.sqlToken + " ;";
950  LocalDateTime r = getDateTimeFromQuery(client, sql);
951 
952  LocalDateTime expected = f.add.apply(Pair.create(enc.clear(d), units));
953  expected = enc.clearForDateAddResult(expected);
954 
955  Fuzzy rc = Fuzzy.compareDateAdd(expected, r, enc);
956  if (resultsToDump.contains(rc)) {
957  System.out.println("Query " + rc + ": " + sql
958  + " -> expected: " + expected.toString() + " got " + r.toString());
959  }
960  }
static LocalDateTime getDateTimeFromQuery(MapdTestClient 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.testDateAdd ( String  fn,
LocalDateTime  d,
DateAddUnit  f,
long  units,
MapdTestClient  client,
Encoding  enc 
) throws Exception
inlinestatic

Definition at line 882 of file DateTimeTest.java.

References 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 void testDateAddTable(String fn, LocalDateTime d, DateAddUnit f, long units, MapdTestClient client, Encoding enc)
static LocalDateTime getDateTimeFromQuery(MapdTestClient 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.testDateAddTable ( String  fn,
LocalDateTime  d,
DateAddUnit  f,
long  units,
MapdTestClient  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 void updateValues(MapdTestClient client, LocalDateTime a, Encoding aEnc)
static LocalDateTime getDateTimeFromQuery(MapdTestClient 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.testDateExtract ( LocalDateTime  d,
DateExtractUnit  f,
MapdTestClient  client,
Encoding  enc 
) throws Exception
inlinestatic

Definition at line 791 of file DateTimeTest.java.

References 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  }
static void testDateExtractTable(LocalDateTime d, DateExtractUnit f, MapdTestClient client, Encoding enc)
static long getLongFromQuery(MapdTestClient 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.testDateExtractTable ( LocalDateTime  d,
DateExtractUnit  f,
MapdTestClient  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(MapdTestClient client, LocalDateTime a, Encoding aEnc)
static long getLongFromQuery(MapdTestClient 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,
MapdTestClient  client,
Encoding  enc 
) throws Exception
inlinestatic

Definition at line 725 of file DateTimeTest.java.

References 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(MapdTestClient client, String sql)
static LocalDateTime testDateTruncTable(LocalDateTime d, DateTruncUnit f, MapdTestClient client, Encoding enc)

+ 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,
MapdTestClient  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 void updateValues(MapdTestClient client, LocalDateTime a, Encoding aEnc)
static LocalDateTime getDateTimeFromQuery(MapdTestClient 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.testDiff ( String  fn,
LocalDateTime  d0,
LocalDateTime  d1,
DateDiffUnit  f,
MapdTestClient  client,
Encoding  enc0,
Encoding  enc1 
) throws Exception
inlinestatic

Definition at line 831 of file DateTimeTest.java.

References 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  }
static void testDiffTable(String fn, LocalDateTime d0, LocalDateTime d1, DateDiffUnit f, MapdTestClient client, Encoding enc0, Encoding enc1)
static long getLongFromQuery(MapdTestClient 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.testDiffTable ( String  fn,
LocalDateTime  d0,
LocalDateTime  d1,
DateDiffUnit  f,
MapdTestClient  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(MapdTestClient client, LocalDateTime a, Encoding aEnc)
static long getLongFromQuery(MapdTestClient 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,
MapdTestClient  client,
Encoding  enc 
) throws Exception
inlinestatic

Definition at line 962 of file DateTimeTest.java.

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

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

964  {
965  if (!addAllowed.contains(f)) {
966  return;
967  }
968 
969  long toSub = -units;
970 
971  String sql =
972  "SELECT " + enc.toSql(d) + " - INTERVAL '" + toSub + "' " + f.sqlToken + " ;";
973  LocalDateTime r = getDateTimeFromQuery(client, sql);
974 
975  LocalDateTime expected = f.add.apply(Pair.create(enc.clear(d), units));
976  expected = enc.clearForDateAddResult(expected);
977 
978  Fuzzy rc = Fuzzy.compareDateAdd(expected, r, enc);
979  if (resultsToDump.contains(rc)) {
980  System.out.println("Query " + rc + ": " + sql
981  + " -> expected: " + expected.toString() + " got " + r.toString());
982  }
983  }
static LocalDateTime getDateTimeFromQuery(MapdTestClient 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.updateValues ( MapdTestClient  client,
LocalDateTime  a,
Encoding  aEnc 
) throws Exception
inlinestaticprivate

Definition at line 746 of file DateTimeTest.java.

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  }
static void updateValues(MapdTestClient client, LocalDateTime a, Encoding aEnc)

+ Here is the caller graph for this function:

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

Definition at line 751 of file DateTimeTest.java.

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 (TOmniSciException e) {
768  System.out.println("Update failed: " + sqlUpdate + " " + e.error_msg);
769  }
770  }

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: