Test IS DISTINCT FROM operator and its variants
| 904 | |
| 905 | // Test IS DISTINCT FROM operator and its variants |
| 906 | void TestDistinctFrom() { |
| 907 | static const string operators[] = {"<=>", "IS DISTINCT FROM", "IS NOT DISTINCT FROM"}; |
| 908 | static const string types[] = {"Boolean", "TinyInt", "SmallInt", "Int", "BigInt", |
| 909 | "Float", "Double", "String", "Timestamp", "Decimal"}; |
| 910 | static const string operands1[] = { |
| 911 | "true", "cast(1 as TinyInt)", "cast(1 as SmallInt)", "cast(1 as Int)", |
| 912 | "cast(1 as BigInt)", "cast(1 as Float)", "cast(1 as Double)", |
| 913 | "'this is a string'", "cast(1 as TimeStamp)", "cast(1 as Decimal)" |
| 914 | }; |
| 915 | static const string operands2[] = { |
| 916 | "false", "cast(2 as TinyInt)", "cast(2 as SmallInt)", "cast(2 as Int)", |
| 917 | "cast(2 as BigInt)", "cast(2 as Float)", "cast(2 as Double)", |
| 918 | "'this is ALSO a string'", "cast(2 as TimeStamp)", "cast(2 as Decimal)" |
| 919 | }; |
| 920 | for (int i = 0; i < sizeof(operators) / sizeof(string); ++i) { |
| 921 | // "IS DISTINCT FROM" and "<=>" are generalized equality, and |
| 922 | // this fact is recorded in is_equal. |
| 923 | const bool is_equal = operators[i] != "IS DISTINCT FROM"; |
| 924 | // Everything IS NOT DISTINCT FROM itself. |
| 925 | for (int j = 0; j < sizeof(types) / sizeof(string); ++j) { |
| 926 | const string operand = "cast(NULL as " + types[j] + ")"; |
| 927 | TestValue(StrCat(operand, " ", operators[i], " ", operand), TYPE_BOOLEAN, |
| 928 | is_equal); |
| 929 | } |
| 930 | for (int j = 0; j < sizeof(operands1) / sizeof(string); ++j) { |
| 931 | TestValue(operands1[j] + ' ' + operators[i] + ' ' + operands1[j], TYPE_BOOLEAN, |
| 932 | is_equal); |
| 933 | } |
| 934 | // NULL IS DISTINCT FROM all non-null things. |
| 935 | for (int j = 0; j < sizeof(operands1) / sizeof(string); ++j) { |
| 936 | TestValue("NULL " + operators[i] + ' ' + operands1[j], TYPE_BOOLEAN, !is_equal); |
| 937 | TestValue(operands1[j] + ' ' + operators[i] + " NULL", TYPE_BOOLEAN, !is_equal); |
| 938 | } |
| 939 | // Non-null values can be DISTINCT. |
| 940 | for (int j = 0; j < sizeof(operands1) / sizeof(string); ++j) { |
| 941 | TestValue(operands1[j] + ' ' + operators[i] + ' ' + operands2[j], TYPE_BOOLEAN, |
| 942 | !is_equal); |
| 943 | } |
| 944 | } |
| 945 | } |
| 946 | |
| 947 | // Test comparison operators with a left or right NULL operand on all types. |
| 948 | void TestNullComparisons() { |