Back to home page

OSCL-LXR

 
 

    


0001 --
0002 -- Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
0003 --
0004 --
0005 -- BOOLEAN
0006 -- https://github.com/postgres/postgres/blob/REL_12_BETA2/src/test/regress/sql/boolean.sql
0007 
0008 --
0009 -- sanity check - if this fails go insane!
0010 --
0011 SELECT 1 AS one;
0012 
0013 
0014 -- ******************testing built-in type bool********************
0015 
0016 -- check bool input syntax
0017 
0018 SELECT true AS true;
0019 
0020 -- [SPARK-28349] We do not need to follow PostgreSQL to support reserved words in column alias
0021 SELECT false AS `false`;
0022 
0023 SELECT boolean('t') AS true;
0024 
0025 SELECT boolean('   f           ') AS `false`;
0026 
0027 SELECT boolean('true') AS true;
0028 
0029 -- [SPARK-27923] PostgreSQL does not accept 'test' but Spark SQL accepts it and sets it to NULL
0030 SELECT boolean('test') AS error;
0031 
0032 SELECT boolean('false') AS `false`;
0033 
0034 -- [SPARK-27923] PostgreSQL does not accept 'foo' but Spark SQL accepts it and sets it to NULL
0035 SELECT boolean('foo') AS error;
0036 
0037 SELECT boolean('y') AS true;
0038 
0039 SELECT boolean('yes') AS true;
0040 
0041 -- [SPARK-27923] PostgreSQL does not accept 'yeah' but Spark SQL accepts it and sets it to NULL
0042 SELECT boolean('yeah') AS error;
0043 
0044 SELECT boolean('n') AS `false`;
0045 
0046 SELECT boolean('no') AS `false`;
0047 
0048 -- [SPARK-27923] PostgreSQL does not accept 'nay' but Spark SQL accepts it and sets it to NULL
0049 SELECT boolean('nay') AS error;
0050 
0051 SELECT boolean('on') AS true;
0052 
0053 SELECT boolean('off') AS `false`;
0054 
0055 SELECT boolean('of') AS `false`;
0056 
0057 -- [SPARK-27923] PostgreSQL does not accept 'o' but Spark SQL accepts it and sets it to NULL
0058 SELECT boolean('o') AS error;
0059 
0060 -- [SPARK-27923] PostgreSQL does not accept 'on_' but Spark SQL accepts it and sets it to NULL
0061 SELECT boolean('on_') AS error;
0062 
0063 -- [SPARK-27923] PostgreSQL does not accept 'off_' but Spark SQL accepts it and sets it to NULL
0064 SELECT boolean('off_') AS error;
0065 
0066 SELECT boolean('1') AS true;
0067 
0068 -- [SPARK-27923] PostgreSQL does not accept '11' but Spark SQL accepts it and sets it to NULL
0069 SELECT boolean('11') AS error;
0070 
0071 SELECT boolean('0') AS `false`;
0072 
0073 -- [SPARK-27923] PostgreSQL does not accept '000' but Spark SQL accepts it and sets it to NULL
0074 SELECT boolean('000') AS error;
0075 
0076 -- [SPARK-27923] PostgreSQL does not accept '' but Spark SQL accepts it and sets it to NULL
0077 SELECT boolean('') AS error;
0078 
0079 -- and, or, not in qualifications
0080 
0081 SELECT boolean('t') or boolean('f') AS true;
0082 
0083 SELECT boolean('t') and boolean('f') AS `false`;
0084 
0085 SELECT not boolean('f') AS true;
0086 
0087 SELECT boolean('t') = boolean('f') AS `false`;
0088 
0089 SELECT boolean('t') <> boolean('f') AS true;
0090 
0091 SELECT boolean('t') > boolean('f') AS true;
0092 
0093 SELECT boolean('t') >= boolean('f') AS true;
0094 
0095 SELECT boolean('f') < boolean('t') AS true;
0096 
0097 SELECT boolean('f') <= boolean('t') AS true;
0098 
0099 -- explicit casts to/from text
0100 SELECT boolean(string('TrUe')) AS true, boolean(string('fAlse')) AS `false`;
0101 SELECT boolean(string('    true   ')) AS true,
0102        boolean(string('     FALSE')) AS `false`;
0103 SELECT string(boolean(true)) AS true, string(boolean(false)) AS `false`;
0104 
0105 -- [SPARK-27923] PostgreSQL does not accept '  tru e ' but Spark SQL accepts it and sets it to NULL
0106 SELECT boolean(string('  tru e ')) AS invalid;    -- error
0107 -- [SPARK-27923] PostgreSQL does not accept '' but Spark SQL accepts it and sets it to NULL
0108 SELECT boolean(string('')) AS invalid;            -- error
0109 
0110 CREATE TABLE BOOLTBL1 (f1 boolean) USING parquet;
0111 
0112 INSERT INTO BOOLTBL1 VALUES (cast('t' as boolean));
0113 
0114 INSERT INTO BOOLTBL1 VALUES (cast('True' as boolean));
0115 
0116 INSERT INTO BOOLTBL1 VALUES (cast('true' as boolean));
0117 
0118 
0119 -- BOOLTBL1 should be full of true's at this point
0120 SELECT '' AS t_3, BOOLTBL1.* FROM BOOLTBL1;
0121 
0122 
0123 SELECT '' AS t_3, BOOLTBL1.*
0124    FROM BOOLTBL1
0125    WHERE f1 = boolean('true');
0126 
0127 
0128 SELECT '' AS t_3, BOOLTBL1.*
0129    FROM BOOLTBL1
0130    WHERE f1 <> boolean('false');
0131 
0132 SELECT '' AS zero, BOOLTBL1.*
0133    FROM BOOLTBL1
0134    WHERE booleq(boolean('false'), f1);
0135 
0136 INSERT INTO BOOLTBL1 VALUES (boolean('f'));
0137 
0138 SELECT '' AS f_1, BOOLTBL1.*
0139    FROM BOOLTBL1
0140    WHERE f1 = boolean('false');
0141 
0142 
0143 CREATE TABLE BOOLTBL2 (f1 boolean) USING parquet;
0144 
0145 INSERT INTO BOOLTBL2 VALUES (boolean('f'));
0146 
0147 INSERT INTO BOOLTBL2 VALUES (boolean('false'));
0148 
0149 INSERT INTO BOOLTBL2 VALUES (boolean('False'));
0150 
0151 INSERT INTO BOOLTBL2 VALUES (boolean('FALSE'));
0152 
0153 -- [SPARK-27923] PostgreSQL does not accept 'XXX' but Spark SQL accepts it and sets it to NULL
0154 -- This is now an invalid expression
0155 -- For pre-v6.3 this evaluated to false - thomas 1997-10-23
0156 INSERT INTO BOOLTBL2
0157    VALUES (boolean('XXX'));
0158 
0159 -- BOOLTBL2 should be full of false's at this point
0160 SELECT '' AS f_4, BOOLTBL2.* FROM BOOLTBL2;
0161 
0162 
0163 SELECT '' AS tf_12, BOOLTBL1.*, BOOLTBL2.*
0164    FROM BOOLTBL1, BOOLTBL2
0165    WHERE BOOLTBL2.f1 <> BOOLTBL1.f1;
0166 
0167 
0168 SELECT '' AS tf_12, BOOLTBL1.*, BOOLTBL2.*
0169    FROM BOOLTBL1, BOOLTBL2
0170    WHERE boolne(BOOLTBL2.f1,BOOLTBL1.f1);
0171 
0172 
0173 SELECT '' AS ff_4, BOOLTBL1.*, BOOLTBL2.*
0174    FROM BOOLTBL1, BOOLTBL2
0175    WHERE BOOLTBL2.f1 = BOOLTBL1.f1 and BOOLTBL1.f1 = boolean('false');
0176 
0177 
0178 SELECT '' AS tf_12_ff_4, BOOLTBL1.*, BOOLTBL2.*
0179    FROM BOOLTBL1, BOOLTBL2
0180    WHERE BOOLTBL2.f1 = BOOLTBL1.f1 or BOOLTBL1.f1 = boolean('true')
0181    ORDER BY BOOLTBL1.f1, BOOLTBL2.f1;
0182 
0183 -- [SPARK-27924] E061-14: Search Conditions
0184 --
0185 -- SQL syntax
0186 -- Try all combinations to ensure that we get nothing when we expect nothing
0187 -- - thomas 2000-01-04
0188 --
0189 
0190 SELECT '' AS True, f1
0191    FROM BOOLTBL1
0192    WHERE f1 IS TRUE;
0193 
0194 SELECT '' AS `Not False`, f1
0195    FROM BOOLTBL1
0196    WHERE f1 IS NOT FALSE;
0197 
0198 SELECT '' AS `False`, f1
0199    FROM BOOLTBL1
0200    WHERE f1 IS FALSE;
0201 
0202 SELECT '' AS `Not True`, f1
0203    FROM BOOLTBL1
0204    WHERE f1 IS NOT TRUE;
0205 
0206 SELECT '' AS `True`, f1
0207    FROM BOOLTBL2
0208    WHERE f1 IS TRUE;
0209 
0210 SELECT '' AS `Not False`, f1
0211    FROM BOOLTBL2
0212    WHERE f1 IS NOT FALSE;
0213 
0214 SELECT '' AS `False`, f1
0215    FROM BOOLTBL2
0216    WHERE f1 IS FALSE;
0217 
0218 SELECT '' AS `Not True`, f1
0219    FROM BOOLTBL2
0220    WHERE f1 IS NOT TRUE;
0221 
0222 --
0223 -- Tests for BooleanTest
0224 --
0225 CREATE TABLE BOOLTBL3 (d string, b boolean, o int) USING parquet;
0226 INSERT INTO BOOLTBL3 VALUES ('true', true, 1);
0227 INSERT INTO BOOLTBL3 VALUES ('false', false, 2);
0228 INSERT INTO BOOLTBL3 VALUES ('null', null, 3);
0229 
0230 -- [SPARK-27924] E061-14: Search Conditions
0231 SELECT
0232     d,
0233     b IS TRUE AS istrue,
0234     b IS NOT TRUE AS isnottrue,
0235     b IS FALSE AS isfalse,
0236     b IS NOT FALSE AS isnotfalse,
0237     b IS UNKNOWN AS isunknown,
0238     b IS NOT UNKNOWN AS isnotunknown
0239 FROM booltbl3 ORDER BY o;
0240 
0241 
0242 -- Test to make sure short-circuiting and NULL handling is
0243 -- correct. Use a table as source to prevent constant simplification
0244 -- to interfer.
0245 CREATE TABLE booltbl4(isfalse boolean, istrue boolean, isnul boolean) USING parquet;
0246 INSERT INTO booltbl4 VALUES (false, true, null);
0247 -- \pset null '(null)'
0248 
0249 -- AND expression need to return null if there's any nulls and not all
0250 -- of the value are true
0251 SELECT istrue AND isnul AND istrue FROM booltbl4;
0252 SELECT istrue AND istrue AND isnul FROM booltbl4;
0253 SELECT isnul AND istrue AND istrue FROM booltbl4;
0254 SELECT isfalse AND isnul AND istrue FROM booltbl4;
0255 SELECT istrue AND isfalse AND isnul FROM booltbl4;
0256 SELECT isnul AND istrue AND isfalse FROM booltbl4;
0257 
0258 -- OR expression need to return null if there's any nulls and none
0259 -- of the value is true
0260 SELECT isfalse OR isnul OR isfalse FROM booltbl4;
0261 SELECT isfalse OR isfalse OR isnul FROM booltbl4;
0262 SELECT isnul OR isfalse OR isfalse FROM booltbl4;
0263 SELECT isfalse OR isnul OR istrue FROM booltbl4;
0264 SELECT istrue OR isfalse OR isnul FROM booltbl4;
0265 SELECT isnul OR istrue OR isfalse FROM booltbl4;
0266 
0267 
0268 --
0269 -- Clean up
0270 -- Many tables are retained by the regression test, but these do not seem
0271 --  particularly useful so just get rid of them for now.
0272 --  - thomas 1997-11-30
0273 --
0274 
0275 DROP TABLE  BOOLTBL1;
0276 
0277 DROP TABLE  BOOLTBL2;
0278 
0279 DROP TABLE  BOOLTBL3;
0280 
0281 DROP TABLE  BOOLTBL4;