@@ -1018,3 +1018,315 @@ def __init__(self):
10181018 FROM illegal_tbl
10191019 WHERE id = 0"""
10201020 self .expected_error = "Parameters must be of the same type"
1021+
1022+
1023+ # GREATEST
1024+ class illarg_greatest_legal (TstView ):
1025+ def __init__ (self ):
1026+ # checked manually
1027+ self .data = [
1028+ {
1029+ "intt" : - 1 ,
1030+ "decimall" : Decimal ("-0.52" ),
1031+ "reall" : Decimal ("-0.1234567" ),
1032+ "dbl" : Decimal ("-0.82711234601246" ),
1033+ "booll" : True ,
1034+ "str" : "hello " ,
1035+ "bin" : "1f8b080000000000ff4b4bcd49492d4a0400218115ac07000000" ,
1036+ "tmestmp" : "2020-06-21T14:23:44.123" ,
1037+ "datee" : "2020-06-21" ,
1038+ "tme" : "14:23:44.456" ,
1039+ "uuidd" : "42b8fec7-c7a3-4531-9611-4bde80f9cb4c" ,
1040+ "arr" : ["ciao" ],
1041+ "mapp" : {"a" : 13 , "b" : 17 },
1042+ }
1043+ ]
1044+ self .sql = """CREATE MATERIALIZED VIEW greatest_legal AS SELECT
1045+ GREATEST(intt, -1) AS intt,
1046+ GREATEST(decimall, -0.52) AS decimall,
1047+ GREATEST(reall, -0.1234567) AS reall,
1048+ GREATEST(dbl, -0.82711234601246) AS dbl,
1049+ GREATEST(booll, FALSE) AS booll,
1050+ GREATEST(str, '0.12') AS str,
1051+ GREATEST(bin, X'1F8B080000000000FF4B4BCD49492D4A0400218115AC07000000') AS bin,
1052+ GREATEST(tmestmp, TIMESTAMP '2020-06-21 14:23:44') AS tmestmp,
1053+ GREATEST(datee, DATE '2020-06-21') AS datee,
1054+ GREATEST(tme, TIME '14:23:44') AS tme,
1055+ GREATEST(uuidd, UUID '42b8fec7-c7a3-4531-9611-4bde80f9cb4c') AS uuidd,
1056+ GREATEST(arr, ARRAY['ciao']) AS arr,
1057+ GREATEST(mapp, MAP['a', 13, 'b', 17]) AS mapp
1058+ FROM illegal_tbl
1059+ WHERE id = 0"""
1060+
1061+
1062+ # Negative Tests
1063+ class illarg_greatest_illegal (TstView ):
1064+ def __init__ (self ):
1065+ # checked manually
1066+ self .sql = """CREATE MATERIALIZED VIEW greatest_illegal AS SELECT
1067+ GREATEST(arr, MAP['a', 13, 'b', 17]) AS arr
1068+ FROM illegal_tbl
1069+ WHERE id = 0"""
1070+ self .expected_error = "Parameters must be of the same type"
1071+
1072+
1073+ class illarg_greatest_illegal1 (TstView ):
1074+ def __init__ (self ):
1075+ # checked manually
1076+ self .sql = """CREATE MATERIALIZED VIEW greatest_illegal1 AS SELECT
1077+ GREATEST(str, False) AS str
1078+ FROM illegal_tbl
1079+ WHERE id = 0"""
1080+ self .expected_error = (
1081+ "cannot infer return type for greatest; operand types: [varchar, boolean]"
1082+ )
1083+
1084+
1085+ # GREATEST_IGNORE_NULLS
1086+ class illarg_greatest_ignore_nulls_legal (TstView ):
1087+ def __init__ (self ):
1088+ # checked manually
1089+ self .data = [
1090+ {
1091+ "intt" : - 1 ,
1092+ "decimall" : Decimal ("-0.52" ),
1093+ "reall" : Decimal ("-0.1234567" ),
1094+ "dbl" : Decimal ("-0.82711234601246" ),
1095+ "booll" : True ,
1096+ "str" : "hello " ,
1097+ "bin" : "1f8b080000000000ff4b4bcd49492d4a0400218115ac07000000" ,
1098+ "tmestmp" : "2020-06-21T14:23:44.123" ,
1099+ "datee" : "2020-06-21" ,
1100+ "tme" : "14:23:44.456" ,
1101+ "uuidd" : "42b8fec7-c7a3-4531-9611-4bde80f9cb4c" ,
1102+ "arr" : ["ciao" ],
1103+ "mapp" : {"a" : 13 , "b" : 17 },
1104+ }
1105+ ]
1106+ self .sql = """CREATE MATERIALIZED VIEW greatest_ignore_nulls_legal AS SELECT
1107+ GREATEST_IGNORE_NULLS(NULL, intt, -1) AS intt,
1108+ GREATEST_IGNORE_NULLS(NULL, decimall, -0.52) AS decimall,
1109+ GREATEST_IGNORE_NULLS(NULL, reall, -0.1234567) AS reall,
1110+ GREATEST_IGNORE_NULLS(NULL, dbl, -0.82711234601246) AS dbl,
1111+ GREATEST_IGNORE_NULLS(NULL, booll, FALSE) AS booll,
1112+ GREATEST_IGNORE_NULLS(NULL, str, '0.12') AS str,
1113+ GREATEST_IGNORE_NULLS(NULL, bin, X'1F8B080000000000FF4B4BCD49492D4A0400218115AC07000000') AS bin,
1114+ GREATEST_IGNORE_NULLS(NULL, tmestmp, TIMESTAMP '2020-06-21 14:23:44') AS tmestmp,
1115+ GREATEST_IGNORE_NULLS(NULL, datee, DATE '2020-06-21') AS datee,
1116+ GREATEST_IGNORE_NULLS(NULL, tme, TIME '14:23:44') AS tme,
1117+ GREATEST_IGNORE_NULLS(NULL, uuidd, UUID '42b8fec7-c7a3-4531-9611-4bde80f9cb4c') AS uuidd,
1118+ GREATEST_IGNORE_NULLS(arr, ARRAY['ciao']) AS arr,
1119+ GREATEST_IGNORE_NULLS(mapp, MAP['a', 13, 'b', 17]) AS mapp
1120+ FROM illegal_tbl
1121+ WHERE id = 0"""
1122+
1123+
1124+ # Negative Test
1125+ class illarg_greatest_ignore_nulls_illegal (TstView ):
1126+ def __init__ (self ):
1127+ # checked manually
1128+ self .sql = """CREATE MATERIALIZED VIEW greatest_ignore_nulls_illegal AS SELECT
1129+ GREATEST_IGNORE_NULLS(mapp, ARRAY['apple']) AS mapp
1130+ FROM illegal_tbl
1131+ WHERE id = 0"""
1132+ self .expected_error = "Parameters must be of the same type"
1133+
1134+
1135+ # LEAST
1136+ class illarg_least_legal (TstView ):
1137+ def __init__ (self ):
1138+ # checked manually
1139+ self .data = [
1140+ {
1141+ "intt" : - 12 ,
1142+ "decimall" : Decimal ("-1111.52" ),
1143+ "reall" : Decimal ("-57681.1796875" ),
1144+ "dbl" : Decimal ("-38.2711234601246" ),
1145+ "booll" : False ,
1146+ "str" : "0.12" ,
1147+ "bin" : "0b1620" ,
1148+ "tmestmp" : "2020-06-21T14:23:44" ,
1149+ "datee" : "2020-06-21" ,
1150+ "tme" : "14:23:44" ,
1151+ "uuidd" : "42b8fec7-c7a3-4531-9611-4bde80f9cb4c" ,
1152+ "arr" : ["apple" ],
1153+ "mapp" : {"a" : 12 , "b" : 17 },
1154+ }
1155+ ]
1156+ self .sql = """CREATE MATERIALIZED VIEW least_legal AS SELECT
1157+ LEAST(intt, -1) AS intt,
1158+ LEAST(decimall, -0.52) AS decimall,
1159+ LEAST(reall, -0.1234567) AS reall,
1160+ LEAST(dbl, -0.82711234601246) AS dbl,
1161+ LEAST(booll, FALSE) AS booll,
1162+ LEAST(str, '0.12') AS str,
1163+ LEAST(bin, X'1F8B080000000000FF4B4BCD49492D4A0400218115AC07000000') AS bin,
1164+ LEAST(tmestmp, TIMESTAMP '2020-06-21 14:23:44') AS tmestmp,
1165+ LEAST(datee, DATE '2020-06-21') AS datee,
1166+ LEAST(tme, TIME '14:23:44') AS tme,
1167+ LEAST(uuidd, UUID '42b8fec7-c7a3-4531-9611-4bde80f9cb4c') AS uuidd,
1168+ LEAST(arr, ARRAY['apple']) AS arr,
1169+ LEAST(mapp, MAP['a', 13, 'b', 17]) AS mapp
1170+ FROM illegal_tbl
1171+ WHERE id = 0"""
1172+
1173+
1174+ # Negative Test
1175+ class illarg_least_illegal (TstView ):
1176+ def __init__ (self ):
1177+ # checked manually
1178+ self .sql = """CREATE MATERIALIZED VIEW least_illegal AS SELECT
1179+ LEAST(mapp, ARRAY['apple']) AS mapp
1180+ FROM illegal_tbl
1181+ WHERE id = 0"""
1182+ self .expected_error = "Parameters must be of the same type"
1183+
1184+
1185+ # LEAST_IGNORE_NULLS
1186+ class illarg_least_ignore_nulls_legal (TstView ):
1187+ def __init__ (self ):
1188+ # checked manually
1189+ self .data = [
1190+ {
1191+ "intt" : - 12 ,
1192+ "decimall" : Decimal ("-1111.52" ),
1193+ "reall" : Decimal ("-57681.1796875" ),
1194+ "dbl" : Decimal ("-38.2711234601246" ),
1195+ "booll" : False ,
1196+ "str" : "0.12" ,
1197+ "bin" : "0b1620" ,
1198+ "tmestmp" : "2020-06-21T14:23:44" ,
1199+ "datee" : "2020-06-21" ,
1200+ "tme" : "14:23:44" ,
1201+ "uuidd" : "42b8fec7-c7a3-4531-9611-4bde80f9cb4c" ,
1202+ "arr" : ["apple" ],
1203+ "mapp" : {"a" : 12 , "b" : 17 },
1204+ }
1205+ ]
1206+ self .sql = """CREATE MATERIALIZED VIEW least_ignore_nulls_legal AS SELECT
1207+ LEAST_IGNORE_NULLS(NULL, intt, -1) AS intt,
1208+ LEAST_IGNORE_NULLS(NULL, decimall, -0.52) AS decimall,
1209+ LEAST_IGNORE_NULLS(NULL, reall, -0.1234567) AS reall,
1210+ LEAST_IGNORE_NULLS(NULL, dbl, -0.82711234601246) AS dbl,
1211+ LEAST_IGNORE_NULLS(NULL, booll, FALSE) AS booll,
1212+ LEAST_IGNORE_NULLS(NULL, str, '0.12') AS str,
1213+ LEAST_IGNORE_NULLS(NULL, bin, X'1F8B080000000000FF4B4BCD49492D4A0400218115AC07000000') AS bin,
1214+ LEAST_IGNORE_NULLS(NULL, tmestmp, TIMESTAMP '2020-06-21 14:23:44') AS tmestmp,
1215+ LEAST_IGNORE_NULLS(NULL, datee, DATE '2020-06-21') AS datee,
1216+ LEAST_IGNORE_NULLS(NULL, tme, TIME '14:23:44') AS tme,
1217+ LEAST_IGNORE_NULLS(NULL, uuidd, UUID '42b8fec7-c7a3-4531-9611-4bde80f9cb4c') AS uuidd,
1218+ LEAST_IGNORE_NULLS(NULL, arr, ARRAY['apple']) AS arr,
1219+ LEAST_IGNORE_NULLS(NULL, mapp, MAP['a', 13, 'b', 17]) AS mapp
1220+ FROM illegal_tbl
1221+ WHERE id = 0"""
1222+
1223+
1224+ # Negative Test
1225+ class illarg_least_ignore_nulls_illegal (TstView ):
1226+ def __init__ (self ):
1227+ # checked manually
1228+ self .sql = """CREATE MATERIALIZED VIEW least_ignore_nulls_illegal AS SELECT
1229+ LEAST_IGNORE_NULLS(NULL, uuidd, X'0B1620') AS uuidd
1230+ FROM illegal_tbl
1231+ WHERE id = 0"""
1232+ self .expected_error = "Parameters must be of the same type"
1233+
1234+
1235+ # IF
1236+ class illarg_if_legal (TstView ):
1237+ def __init__ (self ):
1238+ # checked manually
1239+ self .data = [
1240+ {
1241+ "intt" : "correct" ,
1242+ "decimall" : "correct" ,
1243+ "reall" : "correct" ,
1244+ "dbl" : "correct" ,
1245+ "booll" : "incorrect" ,
1246+ "str" : "incorrect" ,
1247+ "bin" : "correct" ,
1248+ "tmestmp" : "incorrect" ,
1249+ "datee" : "correct" ,
1250+ "tme" : "incorrect" ,
1251+ "uuidd" : "correct" ,
1252+ "arr" : "incorrect" ,
1253+ "mapp" : "correct" ,
1254+ }
1255+ ]
1256+ self .sql = """CREATE MATERIALIZED VIEW if_legal AS SELECT
1257+ IF(intt <= -12, 'correct', 'incorrect') AS intt,
1258+ IF(decimall <= -0.52, 'correct', 'incorrect') AS decimall,
1259+ IF(reall <= -0.1234567, 'correct', 'incorrect') AS reall,
1260+ IF(dbl <= -0.82711234601246, 'correct', 'incorrect') AS dbl,
1261+ IF(booll <= FALSE, 'correct', 'incorrect') AS booll,
1262+ IF(str <= '0.12', 'correct', 'incorrect') AS str,
1263+ IF(bin <= X'1F8B080000000000FF4B4BCD49492D4A0400218115AC07000000', 'correct', 'incorrect') AS bin,
1264+ IF(tmestmp <= TIMESTAMP '2020-06-21 14:23:44', 'correct', 'incorrect') AS tmestmp,
1265+ IF(datee <= DATE '2020-06-21', 'correct', 'incorrect') AS datee,
1266+ IF(tme <= TIME '14:23:44', 'correct', 'incorrect') AS tme,
1267+ IF(uuidd <= UUID'42b8fec7-c7a3-4531-9611-4bde80f9cb4c', 'correct', 'incorrect') AS uuidd,
1268+ IF(arr <= ARRAY['apple'], 'correct', 'incorrect') AS arr,
1269+ IF(mapp <= MAP['a', 13, 'b', 17], 'correct', 'incorrect') AS mapp
1270+ FROM illegal_tbl
1271+ WHERE id = 0"""
1272+
1273+
1274+ # Negative Test
1275+ class illarg_if_illegal (TstView ):
1276+ def __init__ (self ):
1277+ # checked manually
1278+ self .sql = """CREATE MATERIALIZED VIEW if_illegal AS SELECT
1279+ IF(mapp <= ARRAY['apple'], 'correct', 'incorrect') AS mapp
1280+ FROM illegal_tbl
1281+ WHERE id = 0"""
1282+ self .expected_error = "Cannot apply '<=' to arguments of type"
1283+
1284+
1285+ # NULLIF
1286+ class illarg_nullif_legal (TstView ):
1287+ def __init__ (self ):
1288+ # checked manually
1289+ self .data = [
1290+ {
1291+ "intt" : None ,
1292+ "decimall" : Decimal ("-1111.52" ),
1293+ "reall" : Decimal ("-57681.18" ),
1294+ "dbl" : Decimal ("-38.2711234601246" ),
1295+ "booll" : True ,
1296+ "str" : "hello " ,
1297+ "bin" : "0b1620" ,
1298+ "tmestmp" : "2020-06-21T14:23:44.123" ,
1299+ "datee" : None ,
1300+ "tme" : "14:23:44.456" ,
1301+ "uuidd" : None ,
1302+ "arr" : ["bye" , "14" , "See you!" , "-0.52" , None , "14" , "hello " ],
1303+ "mapp" : {"a" : 12 , "b" : 17 },
1304+ }
1305+ ]
1306+ self .sql = """CREATE MATERIALIZED VIEW nullif_legal AS SELECT
1307+ NULLIF(intt, -12) AS intt,
1308+ NULLIF(decimall, -0.52) AS decimall,
1309+ NULLIF(reall, -0.1234567) AS reall,
1310+ NULLIF(dbl, -0.82711234601246) AS dbl,
1311+ NULLIF(booll, FALSE) AS booll,
1312+ NULLIF(str, '0.12') AS str,
1313+ NULLIF(bin, X'1F8B080000000000FF4B4BCD49492D4A0400218115AC07000000') AS bin,
1314+ NULLIF(tmestmp, TIMESTAMP '2020-06-21 14:23:44') AS tmestmp,
1315+ NULLIF(datee, DATE '2020-06-21') AS datee,
1316+ NULLIF(tme, TIME '14:23:44') AS tme,
1317+ NULLIF(uuidd, UUID'42b8fec7-c7a3-4531-9611-4bde80f9cb4c') AS uuidd,
1318+ NULLIF(arr, ARRAY['apple']) AS arr,
1319+ NULLIF(mapp, MAP['a', 13, 'b', 17]) AS mapp
1320+ FROM illegal_tbl
1321+ WHERE id = 0"""
1322+
1323+
1324+ # Negative Test
1325+ class illarg_nullif_illegal (TstView ):
1326+ def __init__ (self ):
1327+ # checked manually
1328+ self .sql = """CREATE MATERIALIZED VIEW nullif_illegal AS SELECT
1329+ NULLIF(mapp, ARRAY['apple']) AS mapp
1330+ FROM illegal_tbl
1331+ WHERE id = 0"""
1332+ self .expected_error = "Cannot apply 'NULLIF' to arguments of type"
0 commit comments