Commit 7c6c55e9 authored by Stefano Petrilli's avatar Stefano Petrilli Committed by Sergei Golubchik

MDEV-34160: Implements ST_LongFromGeoHash

The GIS function ST_LongFromGeoHash takes in input a geohash and returns
its longitude.
The longitude is returned as a numeric value in the interval
[180, -180].
If the argument is NULL, the return value is NULL. If the argument is
invalid, an ER_GIS_INVALID_DATA is thrown.

Author: StefanoPetrilli <stefanop_1999@hotmail.it>
Co-authored-by: default avatarkevincheng2 <chengyf112@gmail.com>
Co-authored-by: default avatarCatalin Besleaga <catalin.besleaga@oracle.com>
Co-authored-by: default avatarGleb Shchepa <gleb.shchepa@oracle.com>
Co-authored-by: default avatarTatiana Azundris Nuernberg <tatjana.nuernberg@oracle.com>
Co-authored-by: default avatarMartin Hansson <martin.hansson@oracle.com>
Co-authored-by: default avatarDeepa Dixit <deepa.dixit@oracle.com>
Co-authored-by: default avatarHans H Melby <hans.h.melby@oracle.com>
Co-authored-by: default avatarJens Even Berg Blomsøy <jens.even.blomsoy@oracle.com>
Co-authored-by: default avatarErlend Dahl <erlend.dahl@oracle.com>
Co-authored-by: default avatarNorvald H. Ryeng <norvald.ryeng@oracle.com>
Co-authored-by: default avatarBennyWang <benny.wang@oracle.com>
Co-authored-by: default avatarDavid.Zhao <david.zhao@oracle.com>
Co-authored-by: default avatarErik Froseth <erik.froseth@oracle.com>
parent 3ac93a19
# valid characters
SELECT ST_LONGFROMGEOHASH("0");
ST_LONGFROMGEOHASH("0")
-158
SELECT ST_LONGFROMGEOHASH("z");
ST_LONGFROMGEOHASH("z")
158
SELECT ST_LONGFROMGEOHASH("0z");
ST_LONGFROMGEOHASH("0z")
-141
SELECT ST_LONGFROMGEOHASH("upbp");
ST_LONGFROMGEOHASH("upbp")
0
SELECT ST_LONGFROMGEOHASH("h000");
ST_LONGFROMGEOHASH("h000")
0
SELECT ST_LONGFROMGEOHASH("s000");
ST_LONGFROMGEOHASH("s000")
0
SELECT ST_LONGFROMGEOHASH("0123456789");
ST_LONGFROMGEOHASH("0123456789")
-179.55743
SELECT ST_LONGFROMGEOHASH("9876543210");
ST_LONGFROMGEOHASH("9876543210")
-107.79609
SELECT ST_LONGFROMGEOHASH("bcdefghjkmnpqrstuvwxyz");
ST_LONGFROMGEOHASH("bcdefghjkmnpqrstuvwxyz")
-142.6078415216915
SELECT ST_LONGFROMGEOHASH("zyxwvutsrqpnmkjhgfedcb");
ST_LONGFROMGEOHASH("zyxwvutsrqpnmkjhgfedcb")
179.55743439816956
SELECT ST_LONGFROMGEOHASH("zzzzzzzzzzzzzzzzzzzz");
ST_LONGFROMGEOHASH("zzzzzzzzzzzzzzzzzzzz")
180
SELECT ST_LONGFROMGEOHASH("pbpbpbpbpbpbpbpbpbpb");
ST_LONGFROMGEOHASH("pbpbpbpbpbpbpbpbpbpb")
180
SELECT ST_LONGFROMGEOHASH("bpbpbpbpbpbpbpbpbpbp");
ST_LONGFROMGEOHASH("bpbpbpbpbpbpbpbpbpbp")
-180
SELECT ST_LONGFROMGEOHASH("00000000000000000000");
ST_LONGFROMGEOHASH("00000000000000000000")
-180
SELECT ST_LONGFROMGEOHASH("rzzzzzzzzzzzzzzzzzzz");
ST_LONGFROMGEOHASH("rzzzzzzzzzzzzzzzzzzz")
180
SELECT ST_LONGFROMGEOHASH("2pbpbpbpbpbpbpbpbpbp");
ST_LONGFROMGEOHASH("2pbpbpbpbpbpbpbpbpbp")
-180
SELECT ST_LONGFROMGEOHASH("7zzzzzzzzzzzzzzzzzzz");
ST_LONGFROMGEOHASH("7zzzzzzzzzzzzzzzzzzz")
0
SELECT ST_LONGFROMGEOHASH("gzzzzzzzzzzzzzzzzzzz");
ST_LONGFROMGEOHASH("gzzzzzzzzzzzzzzzzzzz")
0
SELECT ST_LONGFROMGEOHASH("5bpbpbpbpbpbpbpbpbpb");
ST_LONGFROMGEOHASH("5bpbpbpbpbpbpbpbpbpb")
0
SELECT ST_LONGFROMGEOHASH("0000000000zzzzzzzzzz");
ST_LONGFROMGEOHASH("0000000000zzzzzzzzzz")
-179.999989271164
SELECT ST_LONGFROMGEOHASH("zzzzzzzzzz0000000000");
ST_LONGFROMGEOHASH("zzzzzzzzzz0000000000")
179.999989271164
SELECT ST_LONGFROMGEOHASH("s000000001z7wsg7zzm6");
ST_LONGFROMGEOHASH("s000000001z7wsg7zzm6")
0.00001
SELECT ST_LONGFROMGEOHASH("kpbpbpbpbnpkqe5kpbtm");
ST_LONGFROMGEOHASH("kpbpbpbpbnpkqe5kpbtm")
0.00001
SELECT ST_LONGFROMGEOHASH("ebpbpbpbpcbe9kuebp6d");
ST_LONGFROMGEOHASH("ebpbpbpbpcbe9kuebp6d")
-0.00001
SELECT ST_LONGFROMGEOHASH("7zzzzzzzzy0s37hs00dt");
ST_LONGFROMGEOHASH("7zzzzzzzzy0s37hs00dt")
-0.00001
SELECT ST_LONGFROMGEOHASH("tzzzzzzzzzzzzzzzzzzz");
ST_LONGFROMGEOHASH("tzzzzzzzzzzzzzzzzzzz")
90
SELECT ST_LONGFROMGEOHASH("jzzzzzzzzzzzzzzzzzzz");
ST_LONGFROMGEOHASH("jzzzzzzzzzzzzzzzzzzz")
90
SELECT ST_LONGFROMGEOHASH("9zzzzzzzzzzzzzzzzzzz");
ST_LONGFROMGEOHASH("9zzzzzzzzzzzzzzzzzzz")
-90
SELECT ST_LONGFROMGEOHASH("1zzzzzzzzzzzzzzzzzzz");
ST_LONGFROMGEOHASH("1zzzzzzzzzzzzzzzzzzz")
-90
SELECT ST_LONGFROMGEOHASH("ypzpgxczbzurypzpgxcz");
ST_LONGFROMGEOHASH("ypzpgxczbzurypzpgxcz")
100
SELECT ST_LONGFROMGEOHASH("czbzurypzpgxczbzuryp");
ST_LONGFROMGEOHASH("czbzurypzpgxczbzuryp")
-100
SELECT ST_LONGFROMGEOHASH("0z0z0z0z0z0z0z0z0z0z0z0z0z0z0z0z");
ST_LONGFROMGEOHASH("0z0z0z0z0z0z0z0z0z0z0z0z0z0z0z0z")
-145.16129032258067
SELECT ST_LONGFROMGEOHASH("0123456789bcdefghjkmnpqrstuvwxyz");
ST_LONGFROMGEOHASH("0123456789bcdefghjkmnpqrstuvwxyz")
-179.55743439816956
SELECT ST_LONGFROMGEOHASH("0123456789BCDEFGHJKMNPQRSTUVWXYZ");
ST_LONGFROMGEOHASH("0123456789BCDEFGHJKMNPQRSTUVWXYZ")
-179.55743439816956
SELECT ST_LONGFROMGEOHASH("zyxwvutsrqpnmkjhgfedcb9876543210");
ST_LONGFROMGEOHASH("zyxwvutsrqpnmkjhgfedcb9876543210")
179.55743439816956
SELECT ST_LONGFROMGEOHASH("ZYXWVUTSRQPNMKJHGFEDCB9876543210");
ST_LONGFROMGEOHASH("ZYXWVUTSRQPNMKJHGFEDCB9876543210")
179.55743439816956
SELECT ST_LONGFROMGEOHASH("1e1");
ST_LONGFROMGEOHASH("1e1")
-110
SELECT ST_LONGFROMGEOHASH("100");
ST_LONGFROMGEOHASH("100")
-134
SELECT ST_LONGFROMGEOHASH(CAST(100 AS CHAR));
ST_LONGFROMGEOHASH(CAST(100 AS CHAR))
-134
SELECT ST_LONGFROMGEOHASH("10111000110001111001");
ST_LONGFROMGEOHASH("10111000110001111001")
-133.549761770805
SELECT ST_LONGFROMGEOHASH("11111111111111111111");
ST_LONGFROMGEOHASH("11111111111111111111")
-133.548387096774
SELECT ST_LONGFROMGEOHASH("99999999999999999999");
ST_LONGFROMGEOHASH("99999999999999999999")
-110.3225806451612
SELECT ST_LONGFROMGEOHASH(CAST("012" AS BINARY));
ST_LONGFROMGEOHASH(CAST("012" AS BINARY))
-179
SELECT ST_LONGFROMGEOHASH(NULL);
ST_LONGFROMGEOHASH(NULL)
NULL
SELECT ST_LONGFROMGEOHASH(null);
ST_LONGFROMGEOHASH(null)
NULL
# invalid characters and inputs
SELECT ST_LONGFROMGEOHASH("0123a45");
ERROR HY000: Incorrect geohash value: '0123a45' for function st_longfromgeohash
SELECT ST_LONGFROMGEOHASH("xyzi");
ERROR HY000: Incorrect geohash value: 'xyzi' for function st_longfromgeohash
SELECT ST_LONGFROMGEOHASH("zyxLwv");
ERROR HY000: Incorrect geohash value: 'zyxLwv' for function st_longfromgeohash
SELECT ST_LONGFROMGEOHASH("bcdjo");
ERROR HY000: Incorrect geohash value: 'bcdjo' for function st_longfromgeohash
SELECT ST_LONGFROMGEOHASH("zyx**wv");
ERROR HY000: Incorrect geohash value: 'zyx**wv' for function st_longfromgeohash
SELECT ST_LONGFROMGEOHASH("1 2 3 4");
ERROR HY000: Incorrect geohash value: '1 2 3 4' for function st_longfromgeohash
SELECT ST_LONGFROMGEOHASH("1''2345");
ERROR HY000: Incorrect geohash value: '1''2345' for function st_longfromgeohash
SELECT ST_LONGFROMGEOHASH("12.345");
ERROR HY000: Incorrect geohash value: '12.345' for function st_longfromgeohash
SELECT ST_LONGFROMGEOHASH(" ");
ERROR HY000: Incorrect geohash value: ' ' for function st_longfromgeohash
SELECT ST_LONGFROMGEOHASH("NULL");
ERROR HY000: Incorrect geohash value: 'NULL' for function st_longfromgeohash
SELECT ST_LONGFROMGEOHASH("0a 0d");
ERROR HY000: Incorrect geohash value: '0a 0d' for function st_longfromgeohash
SELECT ST_LONGFROMGEOHASH("-100");
ERROR HY000: Incorrect geohash value: '-100' for function st_longfromgeohash
SELECT ST_LONGFROMGEOHASH("");
ERROR HY000: Incorrect geohash value: '' for function st_longfromgeohash
SELECT ST_LONGFROMGEOHASH(9876543210);
ERROR 22023: Invalid GIS data provided to function ST_LongFromGeoHas.
SELECT ST_LONGFROMGEOHASH(0123456789);
ERROR 22023: Invalid GIS data provided to function ST_LongFromGeoHas.
SELECT ST_LONGFROMGEOHASH(1e1);
ERROR 22023: Invalid GIS data provided to function ST_LongFromGeoHas.
SELECT ST_LONGFROMGEOHASH();
ERROR 42000: Incorrect parameter count in the call to native function 'ST_LONGFROMGEOHASH'
SELECT ST_LONGFROMGEOHASH("123","456");
ERROR 42000: Incorrect parameter count in the call to native function 'ST_LONGFROMGEOHASH'
SELECT ST_LONGFROMGEOHASH("123",);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1
SELECT ST_LONGFROMGEOHASH(,"456");
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '"456")' at line 1
SELECT ST_LONGFROMGEOHASH(,);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1
SELECT ST_LONGFROMGEOHASH("0123456"789);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '789)' at line 1
SELECT ST_LONGFROMGEOHASH(abcdef);
ERROR 42S22: Unknown column 'abcdef' in 'field list'
# very long geohash
SELECT ST_LONGFROMGEOHASH("0123456789bcdefghjkmnpqrstuvwxyz0123456789bcdefghjkm"
"npqrstuvwxyz0123456789bcdefghjkmnpqrstuvwxyz01234567"
"89bcdefghjkmnpqrstuvwxyz");
ST_LONGFROMGEOHASH("0123456789bcdefghjkmnpqrstuvwxyz0123456789bcdefghjkm"
"npqrstuvwxyz0123456789bcdefghjkmnpqrstuvwxyz01234567"
"89bcdefghjkmnpqrstuvwxyz")
-179.55743439816956
SELECT ST_LONGFROMGEOHASH("0123456789BCDEFGHJKMNPQRSTUVWXYZ0123456789BCDEFGHJKM"
"NPQRSTUVWXYZ0123456789BCDEFGHJKMNPQRSTUVWXYZ01234567"
"89BCDEFGHJKMNPQRSTUVWXYZ");
ST_LONGFROMGEOHASH("0123456789BCDEFGHJKMNPQRSTUVWXYZ0123456789BCDEFGHJKM"
"NPQRSTUVWXYZ0123456789BCDEFGHJKMNPQRSTUVWXYZ01234567"
"89BCDEFGHJKMNPQRSTUVWXYZ")
-179.55743439816956
SELECT ST_LONGFROMGEOHASH("zyxwvutsrqpnmkjhgfedcb9876543210zyxwvutsrqpnmkjhgfed"
"cb9876543210zyxwvutsrqpnmkjhgfedcb9876543210zyxwvuts"
"rqpnmkjhgfedcb9876543210");
ST_LONGFROMGEOHASH("zyxwvutsrqpnmkjhgfedcb9876543210zyxwvutsrqpnmkjhgfed"
"cb9876543210zyxwvutsrqpnmkjhgfedcb9876543210zyxwvuts"
"rqpnmkjhgfedcb9876543210")
179.55743439816956
SELECT ST_LONGFROMGEOHASH("ZYXWVUTSRQPNMKJHGFEDCB9876543210ZYXWVUTSRQPNMKJHGFED"
"CB9876543210ZYXWVUTSRQPNMKJHGFEDCB9876543210ZYXWVUTS"
"RQPNMKJHGFEDCB9876543210");
ST_LONGFROMGEOHASH("ZYXWVUTSRQPNMKJHGFEDCB9876543210ZYXWVUTSRQPNMKJHGFED"
"CB9876543210ZYXWVUTSRQPNMKJHGFEDCB9876543210ZYXWVUTS"
"RQPNMKJHGFEDCB9876543210")
179.55743439816956
CREATE TABLE geohashes (gid INT NOT NULL PRIMARY KEY, hash_value VARCHAR(255));
INSERT INTO geohashes VALUES
(1, "000000000000000000000"),
......@@ -18,6 +230,27 @@ INSERT INTO geohashes VALUES
(16, "vqghx20fx6d8r5vfkbgf"),
(17, "wvetm3u23kr9r6663k31"),
(18, "e5t2p7sk291vpyb08pwu");
# different random geohash values
SELECT ST_LONGFROMGEOHASH(hash_value) FROM geohashes;
ST_LONGFROMGEOHASH(hash_value)
-180
180
NULL
1
-0.1
1
-158
158
-105.343666081393
75.4258807526218
113.2506169687463
4.4253282778628
-113.9241805635394
-132.9724051824284
102.7417962437673
60.7886982739903
128.908488386749
-37.292723368146
# valid characters
SELECT ST_LATFROMGEOHASH("0");
ST_LATFROMGEOHASH("0")
......@@ -333,7 +566,7 @@ ST_GEOHASH(180,NULL,10)
NULL
SELECT ST_GEOHASH(180,90,NULL);
ST_GEOHASH(180,90,NULL)
NULL
zzzzzzzzzzzzzzzzzzzzzz
SELECT ST_GEOHASH(ST_GEOMFROMTEXT('POINT(0 0)'),10);
ST_GEOHASH(ST_GEOMFROMTEXT('POINT(0 0)'),10)
s000000000
......@@ -411,7 +644,7 @@ ST_GEOHASH(NULL,100)
NULL
SELECT ST_GEOHASH(ST_GEOMFROMTEXT('POINT(-0.0001 -0.0001)'),NULL);
ST_GEOHASH(ST_GEOMFROMTEXT('POINT(-0.0001 -0.0001)'),NULL)
NULL
7zzzzzzzmtm7mzm00yd7z00s0y30g60000000000000000000000000000000000000000000000000000000000000000000000
SELECT ST_GEOHASH(ST_DIFFERENCE(ST_GEOMFROMTEXT('POINT(180 90)'),ST_GEOMFROMTEXT('POINT(0 0)')),20);
ST_GEOHASH(ST_DIFFERENCE(ST_GEOMFROMTEXT('POINT(180 90)'),ST_GEOMFROMTEXT('POINT(0 0)')),20)
zzzzzzzzzzzzzzzzzzzz
......@@ -613,5 +846,360 @@ SELECT ST_GEOHASH(ST_DIFFERENCE(ST_GEOMFROMTEXT('POINT(180 90)'),ST_GEOMFROMTEXT
ERROR 22023: Invalid GIS data provided to function ST_GeoHash.
SELECT ST_GEOHASH(ST_SYMDIFFERENCE(ST_GEOMFROMTEXT('POINT(180 90)'),ST_GEOMFROMTEXT('POINT(0 0)')),20);
ERROR 22023: Invalid GIS data provided to function ST_GeoHash.
#=============================================================
# ST_LONGFROMGEOHASH()
#=============================================================
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(180,90,20));
ST_LONGFROMGEOHASH(ST_GEOHASH(180,90,20))
180
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(180,-90,20));
ST_LONGFROMGEOHASH(ST_GEOHASH(180,-90,20))
180
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(-180,90,20));
ST_LONGFROMGEOHASH(ST_GEOHASH(-180,90,20))
-180
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(-180,-90,20));
ST_LONGFROMGEOHASH(ST_GEOHASH(-180,-90,20))
-180
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(180,0,20));
ST_LONGFROMGEOHASH(ST_GEOHASH(180,0,20))
180
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(-180,0,20));
ST_LONGFROMGEOHASH(ST_GEOHASH(-180,0,20))
-180
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(-0,0,20));
ST_LONGFROMGEOHASH(ST_GEOHASH(-0,0,20))
0
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(0.10,90,20));
ST_LONGFROMGEOHASH(ST_GEOHASH(0.10,90,20))
0.1
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(100,45,20));
ST_LONGFROMGEOHASH(ST_GEOHASH(100,45,20))
100
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(179.999999,90,20));
ST_LONGFROMGEOHASH(ST_GEOHASH(179.999999,90,20))
179.999999
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(-179.999999,0,20));
ST_LONGFROMGEOHASH(ST_GEOHASH(-179.999999,0,20))
-179.999999
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(18*10,900/10,20));
ST_LONGFROMGEOHASH(ST_GEOHASH(18*10,900/10,20))
180
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(100 10)'),10));
ST_LONGFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(100 10)'),10))
100
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(10 10)'),10));
ST_LONGFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(10 10)'),10))
10
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(-10 10)'),10));
ST_LONGFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(-10 10)'),10))
-10
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(1.000 10)'),10));
ST_LONGFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(1.000 10)'),10))
1
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(-1.000 10)'),10));
ST_LONGFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(-1.000 10)'),10))
-1
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(1.00101 90)'),20));
ST_LONGFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(1.00101 90)'),20))
1.00101
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(-1.00101 90)'),20));
ST_LONGFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(-1.00101 90)'),20))
-1.00101
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(20 20)'),10));
ST_LONGFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(20 20)'),10))
20
#=============================================================
# ST_LATFROMGEOHASH()
#=============================================================
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(180,90,20));
ST_LATFROMGEOHASH(ST_GEOHASH(180,90,20))
90
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(180,-90,20));
ST_LATFROMGEOHASH(ST_GEOHASH(180,-90,20))
-90
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(-180,90,20));
ST_LATFROMGEOHASH(ST_GEOHASH(-180,90,20))
90
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(-180,-90,20));
ST_LATFROMGEOHASH(ST_GEOHASH(-180,-90,20))
-90
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(0,90,20));
ST_LATFROMGEOHASH(ST_GEOHASH(0,90,20))
90
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(0,-90,20));
ST_LATFROMGEOHASH(ST_GEOHASH(0,-90,20))
-90
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(0,-0,20));
ST_LATFROMGEOHASH(ST_GEOHASH(0,-0,20))
0
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(180,0.101,20));
ST_LATFROMGEOHASH(ST_GEOHASH(180,0.101,20))
0.101
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(100,45,20));
ST_LATFROMGEOHASH(ST_GEOHASH(100,45,20))
45
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(180,89.99999990,20));
ST_LATFROMGEOHASH(ST_GEOHASH(180,89.99999990,20))
89.9999999
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(0,89.999999,20));
ST_LATFROMGEOHASH(ST_GEOHASH(0,89.999999,20))
89.999999
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(18*10,900/10,20));
ST_LATFROMGEOHASH(ST_GEOHASH(18*10,900/10,20))
90
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(10 50)'),10));
ST_LATFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(10 50)'),10))
50
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(10 10)'),10));
ST_LATFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(10 10)'),10))
10
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(10 -10)'),10));
ST_LATFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(10 -10)'),10))
-10
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(10 1.000)'),10));
ST_LATFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(10 1.000)'),10))
1
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(10 -1.0000)'),10));
ST_LATFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(10 -1.0000)'),10))
-1
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(180 1.00101)'),20));
ST_LATFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(180 1.00101)'),20))
1.00101
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(-100 -1.00101)'),20));
ST_LATFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(-100 -1.00101)'),20))
-1.00101
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(20 -20)'),10));
ST_LATFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(20 -20)'),10))
-20
#=============================================================
# ST_GEOHASH()
#=============================================================
SELECT ST_GEOHASH(ST_LONGFROMGEOHASH("zzzzzzzzzzzzzzzzzzzz"),ST_LATFROMGEOHASH("zzzzzzzzzzzzzzzzzzzz"),20);
ST_GEOHASH(ST_LONGFROMGEOHASH("zzzzzzzzzzzzzzzzzzzz"),ST_LATFROMGEOHASH("zzzzzzzzzzzzzzzzzzzz"),20)
zzzzzzzzzzzzzzzzzzzz
SELECT ST_GEOHASH(ST_LONGFROMGEOHASH("00000000000000000000"),ST_LATFROMGEOHASH("00000000000000000000"),20);
ST_GEOHASH(ST_LONGFROMGEOHASH("00000000000000000000"),ST_LATFROMGEOHASH("00000000000000000000"),20)
00000000000000000000
SELECT ST_GEOHASH(ST_LONGFROMGEOHASH("zzzzzzzzzzzzzzzzzzzz"),ST_LATFROMGEOHASH("00000000000000000000"),20);
ST_GEOHASH(ST_LONGFROMGEOHASH("zzzzzzzzzzzzzzzzzzzz"),ST_LATFROMGEOHASH("00000000000000000000"),20)
pbpbpbpbpbpbpbpbpbpb
SELECT ST_GEOHASH(ST_LONGFROMGEOHASH("00000000000000000000"),ST_LATFROMGEOHASH("zzzzzzzzzzzzzzzzzzzz"),20);
ST_GEOHASH(ST_LONGFROMGEOHASH("00000000000000000000"),ST_LATFROMGEOHASH("zzzzzzzzzzzzzzzzzzzz"),20)
bpbpbpbpbpbpbpbpbpbp
SELECT ST_GEOHASH(ST_LONGFROMGEOHASH("pbpbpbpbpbpbpbpbpbpb"),ST_LATFROMGEOHASH("zzzzzzzzzzzzzzzzzzzz"),20);
ST_GEOHASH(ST_LONGFROMGEOHASH("pbpbpbpbpbpbpbpbpbpb"),ST_LATFROMGEOHASH("zzzzzzzzzzzzzzzzzzzz"),20)
zzzzzzzzzzzzzzzzzzzz
SELECT ST_GEOHASH(ST_LONGFROMGEOHASH("zzzzzzzzzzzzzzzzzzzz"),ST_LATFROMGEOHASH("pbpbpbpbpbpbpbpbpbpb"),20);
ST_GEOHASH(ST_LONGFROMGEOHASH("zzzzzzzzzzzzzzzzzzzz"),ST_LATFROMGEOHASH("pbpbpbpbpbpbpbpbpbpb"),20)
pbpbpbpbpbpbpbpbpbpb
SELECT ST_GEOHASH(ST_LONGFROMGEOHASH("zzzzzzzzzzzzzzzzzzzz"),ST_LATFROMGEOHASH("bpbpbpbpbpbpbpbpbpbp"),20);
ST_GEOHASH(ST_LONGFROMGEOHASH("zzzzzzzzzzzzzzzzzzzz"),ST_LATFROMGEOHASH("bpbpbpbpbpbpbpbpbpbp"),20)
zzzzzzzzzzzzzzzzzzzz
SELECT ST_GEOHASH(ST_LONGFROMGEOHASH("bpbpbpbpbpbpbpbpbpbp"),ST_LATFROMGEOHASH("zzzzzzzzzzzzzzzzzzzz"),20);
ST_GEOHASH(ST_LONGFROMGEOHASH("bpbpbpbpbpbpbpbpbpbp"),ST_LATFROMGEOHASH("zzzzzzzzzzzzzzzzzzzz"),20)
bpbpbpbpbpbpbpbpbpbp
SELECT ST_GEOHASH(ST_LONGFROMGEOHASH("bpbpbpbpbpbpbpbpbpbp"),ST_LATFROMGEOHASH("pbpbpbpbpbpbpbpbpbpb"),20);
ST_GEOHASH(ST_LONGFROMGEOHASH("bpbpbpbpbpbpbpbpbpbp"),ST_LATFROMGEOHASH("pbpbpbpbpbpbpbpbpbpb"),20)
00000000000000000000
SELECT
ST_LONGFROMGEOHASH(
CAST("0123456789bcdefghjkmnpqrstuvwxyz0123456789BCDEFGHJKMNPQRSTUVWXYZ"
AS CHAR CHARACTER SET utf8) COLLATE utf8_persian_ci);
ST_LONGFROMGEOHASH(
CAST("0123456789bcdefghjkmnpqrstuvwxyz0123456789BCDEFGHJKMNPQRSTUVWXYZ"
AS CHAR CHARACTER SET utf8) COLLATE utf8_persian_ci)
-179.55743439816956
SELECT
ST_LONGFROMGEOHASH(
CAST("0123456789bcdefghjkmnpqrstuvwxyz0123456789BCDEFGHJKMNPQRSTUVWXYZ"
AS CHAR CHARACTER SET utf8) COLLATE utf8_czech_ci);
ST_LONGFROMGEOHASH(
CAST("0123456789bcdefghjkmnpqrstuvwxyz0123456789BCDEFGHJKMNPQRSTUVWXYZ"
AS CHAR CHARACTER SET utf8) COLLATE utf8_czech_ci)
-179.55743439816956
SELECT
ST_LONGFROMGEOHASH(
CAST("0123456789bcdefghjkmnpqrstuvwxyz0123456789BCDEFGHJKMNPQRSTUVWXYZ"
AS CHAR CHARACTER SET utf8) COLLATE utf8_unicode_ci);
ST_LONGFROMGEOHASH(
CAST("0123456789bcdefghjkmnpqrstuvwxyz0123456789BCDEFGHJKMNPQRSTUVWXYZ"
AS CHAR CHARACTER SET utf8) COLLATE utf8_unicode_ci)
-179.55743439816956
SELECT
ST_LONGFROMGEOHASH(
CAST("0123456789bcdefghjkmnpqrstuvwxyz0123456789BCDEFGHJKMNPQRSTUVWXYZ"
AS CHAR CHARACTER SET utf8) COLLATE utf8_hungarian_ci);
ST_LONGFROMGEOHASH(
CAST("0123456789bcdefghjkmnpqrstuvwxyz0123456789BCDEFGHJKMNPQRSTUVWXYZ"
AS CHAR CHARACTER SET utf8) COLLATE utf8_hungarian_ci)
-179.55743439816956
SELECT
ST_LATFROMGEOHASH(
CAST("0123456789bcdefghjkmnpqrstuvwxyz0123456789BCDEFGHJKMNPQRSTUVWXYZ"
AS CHAR CHARACTER SET utf8) COLLATE utf8_persian_ci);
ST_LATFROMGEOHASH(
CAST("0123456789bcdefghjkmnpqrstuvwxyz0123456789BCDEFGHJKMNPQRSTUVWXYZ"
AS CHAR CHARACTER SET utf8) COLLATE utf8_persian_ci)
-82.77450549262497
SELECT
ST_LATFROMGEOHASH(
CAST("0123456789bcdefghjkmnpqrstuvwxyz0123456789BCDEFGHJKMNPQRSTUVWXYZ"
AS CHAR CHARACTER SET utf8) COLLATE utf8_czech_ci);
ST_LATFROMGEOHASH(
CAST("0123456789bcdefghjkmnpqrstuvwxyz0123456789BCDEFGHJKMNPQRSTUVWXYZ"
AS CHAR CHARACTER SET utf8) COLLATE utf8_czech_ci)
-82.77450549262497
SELECT
ST_LATFROMGEOHASH(
CAST("0123456789bcdefghjkmnpqrstuvwxyz0123456789BCDEFGHJKMNPQRSTUVWXYZ"
AS CHAR CHARACTER SET utf8) COLLATE utf8_unicode_ci);
ST_LATFROMGEOHASH(
CAST("0123456789bcdefghjkmnpqrstuvwxyz0123456789BCDEFGHJKMNPQRSTUVWXYZ"
AS CHAR CHARACTER SET utf8) COLLATE utf8_unicode_ci)
-82.77450549262497
SELECT
ST_LATFROMGEOHASH(
CAST("0123456789bcdefghjkmnpqrstuvwxyz0123456789BCDEFGHJKMNPQRSTUVWXYZ"
AS CHAR CHARACTER SET utf8) COLLATE utf8_hungarian_ci);
ST_LATFROMGEOHASH(
CAST("0123456789bcdefghjkmnpqrstuvwxyz0123456789BCDEFGHJKMNPQRSTUVWXYZ"
AS CHAR CHARACTER SET utf8) COLLATE utf8_hungarian_ci)
-82.77450549262497
CREATE TABLE t1 (val DOUBLE);
INSERT INTO t1 (val) VALUES (12.2);
SELECT val INTO @double FROM t1;
DROP TABLE t1;
SET @null = NULL;
SET @geohash = "01bbgcee";
PREPARE stmt FROM "SELECT ST_LONGFROMGEOHASH(?)";
EXECUTE stmt USING @geohash;
ST_LONGFROMGEOHASH(?)
-178.7755
DEALLOCATE PREPARE stmt;
SELECT ST_LONGFROMGEOHASH(@geohash);
ST_LONGFROMGEOHASH(@geohash)
-178.7755
SELECT ST_LONGFROMGEOHASH(@null);
ST_LONGFROMGEOHASH(@null)
NULL
PREPARE stmt FROM "SELECT ST_LATFROMGEOHASH(?)";
EXECUTE stmt USING @geohash;
ST_LATFROMGEOHASH(?)
-80.0156
DEALLOCATE PREPARE stmt;
SELECT ST_LATFROMGEOHASH(@geohash);
ST_LATFROMGEOHASH(@geohash)
-80.0156
SELECT ST_LATFROMGEOHASH(@null);
ST_LATFROMGEOHASH(@null)
NULL
SET @maxlen = 3;
PREPARE stmt FROM "SELECT ST_GeoHash(POINT(10, 10), ?)";
EXECUTE stmt USING @maxlen;
ST_GeoHash(POINT(10, 10), ?)
s1z
DEALLOCATE PREPARE stmt;
SELECT ST_GeoHash(POINT(10, 10), @maxlen);
ST_GeoHash(POINT(10, 10), @maxlen)
s1z
SELECT ST_GeoHash(POINT(10, 10), @null);
ST_GeoHash(POINT(10, 10), @null)
s1z0gs3y0zh7w1z0gs3y0zw
SET @point = POINT(10, 10);
PREPARE stmt FROM "SELECT ST_GeoHash(?, 10)";
EXECUTE stmt USING @point;
ST_GeoHash(?, 10)
s1z0gs3y0z
DEALLOCATE PREPARE stmt;
SELECT ST_GeoHash(@point, 10);
ST_GeoHash(@point, 10)
s1z0gs3y0z
SELECT ST_GeoHash(@null, 10);
ST_GeoHash(@null, 10)
NULL
SET @long = 22.0311;
PREPARE stmt FROM "SELECT ST_GeoHash(?, 10, 10)";
EXECUTE stmt USING @long;
ST_GeoHash(?, 10, 10)
s3z8vk6w1z
DEALLOCATE PREPARE stmt;
SELECT ST_GeoHash(@long, 10, 10);
ST_GeoHash(@long, 10, 10)
s3z8vk6w1z
SELECT ST_GeoHash(@null, 10, 10);
ST_GeoHash(@null, 10, 10)
NULL
SET @lat = -54.123;
PREPARE stmt FROM "SELECT ST_GeoHash(10, ?, 10)";
EXECUTE stmt USING @lat;
ST_GeoHash(10, ?, 10)
hnrh5e1y8v
DEALLOCATE PREPARE stmt;
SELECT ST_GeoHash(10, @lat, 10);
ST_GeoHash(10, @lat, 10)
hnrh5e1y8v
SELECT ST_GeoHash(10, @null, 10);
ST_GeoHash(10, @null, 10)
NULL
PREPARE stmt FROM "SELECT ST_GeoHash(10, 10, ?)";
EXECUTE stmt USING @maxlen;
ST_GeoHash(10, 10, ?)
s1z
DEALLOCATE PREPARE stmt;
SELECT ST_GeoHash(10, 10, @maxlen);
ST_GeoHash(10, 10, @maxlen)
s1z
SELECT ST_GeoHash(@double, @double, 10);
ST_GeoHash(@double, @double, 10)
s60tmsgy0s
SELECT ST_GeoHash(POINT(10, 10), @double);
ERROR 22023: Invalid GIS data provided to function ST_GeoHash.
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a VARCHAR(255));
INSERT INTO t1 (a) VALUES (' ');
SELECT ST_LONGFROMGEOHASH(a) FROM t1;
ERROR HY000: Incorrect geohash value: ' ' for function st_longfromgeohash
SELECT ST_LATFROMGEOHASH(a) FROM t1;
ERROR HY000: Incorrect geohash value: ' ' for function st_latfromgeohash
DELETE FROM t1;
INSERT INTO t1 VALUES ('swpwwwwww'), ('guqtjvooguqtjvoo');
SELECT ST_LONGFROMGEOHASH(a) FROM t1;
ERROR HY000: Incorrect geohash value: 'guqtjvooguqtjvoo' for function st_longfromgeohash
SELECT ST_LATFROMGEOHASH(a) FROM t1;
ERROR HY000: Incorrect geohash value: 'guqtjvooguqtjvoo' for function st_latfromgeohash
# Clean up
DROP TABLE geohashes;
DROP TABLE t1;
#
# Bug#22838668 CRASH IN ITEM_FUNC_LATLONGFROMGEOHASH::VAL_REAL
# WITH BAD PARAMETERS
#
DO ST_Disjoint(
POLYGON(
LINESTRING(POINT(1, 1))
),
ST_LatFromGeoHash(ExtractValue(1, NULL))
);
ERROR HY000: Illegal parameter data type double for operation 'st_disjoint'
DO ST_Disjoint(
POLYGON(
LINESTRING(POINT(1, 1))
),
ST_LongFromGeoHash(ExtractValue(1, NULL))
);
ERROR HY000: Illegal parameter data type double for operation 'st_disjoint'
DO ST_Disjoint(
POLYGON(
LINESTRING(POINT(1, 1))
),
ST_LatFromGeoHash(UpdateXML(1, NULL, NULL))
);
ERROR HY000: Illegal parameter data type double for operation 'st_disjoint'
DO ST_Disjoint(
POLYGON(
LINESTRING(POINT(1, 1))
),
ST_LongFromGeoHash(UpdateXML(1, NULL, NULL))
);
ERROR HY000: Illegal parameter data type double for operation 'st_disjoint'
......@@ -17,6 +17,191 @@
-- disable_warnings
#####################################################################
# ST_LONGFROMGEOHASH()
#####################################################################
# Check for all valid characters and inputs
--echo # valid characters
SELECT ST_LONGFROMGEOHASH("0");
SELECT ST_LONGFROMGEOHASH("z");
SELECT ST_LONGFROMGEOHASH("0z");
SELECT ST_LONGFROMGEOHASH("upbp");
SELECT ST_LONGFROMGEOHASH("h000");
SELECT ST_LONGFROMGEOHASH("s000");
SELECT ST_LONGFROMGEOHASH("0123456789");
SELECT ST_LONGFROMGEOHASH("9876543210");
SELECT ST_LONGFROMGEOHASH("bcdefghjkmnpqrstuvwxyz");
SELECT ST_LONGFROMGEOHASH("zyxwvutsrqpnmkjhgfedcb");
SELECT ST_LONGFROMGEOHASH("zzzzzzzzzzzzzzzzzzzz");
SELECT ST_LONGFROMGEOHASH("pbpbpbpbpbpbpbpbpbpb");
SELECT ST_LONGFROMGEOHASH("bpbpbpbpbpbpbpbpbpbp");
SELECT ST_LONGFROMGEOHASH("00000000000000000000");
SELECT ST_LONGFROMGEOHASH("rzzzzzzzzzzzzzzzzzzz");
SELECT ST_LONGFROMGEOHASH("2pbpbpbpbpbpbpbpbpbp");
SELECT ST_LONGFROMGEOHASH("7zzzzzzzzzzzzzzzzzzz");
SELECT ST_LONGFROMGEOHASH("gzzzzzzzzzzzzzzzzzzz");
SELECT ST_LONGFROMGEOHASH("5bpbpbpbpbpbpbpbpbpb");
SELECT ST_LONGFROMGEOHASH("0000000000zzzzzzzzzz");
SELECT ST_LONGFROMGEOHASH("zzzzzzzzzz0000000000");
SELECT ST_LONGFROMGEOHASH("s000000001z7wsg7zzm6");
SELECT ST_LONGFROMGEOHASH("kpbpbpbpbnpkqe5kpbtm");
SELECT ST_LONGFROMGEOHASH("ebpbpbpbpcbe9kuebp6d");
SELECT ST_LONGFROMGEOHASH("7zzzzzzzzy0s37hs00dt");
SELECT ST_LONGFROMGEOHASH("tzzzzzzzzzzzzzzzzzzz");
SELECT ST_LONGFROMGEOHASH("jzzzzzzzzzzzzzzzzzzz");
SELECT ST_LONGFROMGEOHASH("9zzzzzzzzzzzzzzzzzzz");
SELECT ST_LONGFROMGEOHASH("1zzzzzzzzzzzzzzzzzzz");
SELECT ST_LONGFROMGEOHASH("ypzpgxczbzurypzpgxcz");
SELECT ST_LONGFROMGEOHASH("czbzurypzpgxczbzuryp");
SELECT ST_LONGFROMGEOHASH("0z0z0z0z0z0z0z0z0z0z0z0z0z0z0z0z");
SELECT ST_LONGFROMGEOHASH("0123456789bcdefghjkmnpqrstuvwxyz");
SELECT ST_LONGFROMGEOHASH("0123456789BCDEFGHJKMNPQRSTUVWXYZ");
SELECT ST_LONGFROMGEOHASH("zyxwvutsrqpnmkjhgfedcb9876543210");
SELECT ST_LONGFROMGEOHASH("ZYXWVUTSRQPNMKJHGFEDCB9876543210");
SELECT ST_LONGFROMGEOHASH("1e1");
SELECT ST_LONGFROMGEOHASH("100");
SELECT ST_LONGFROMGEOHASH(CAST(100 AS CHAR));
SELECT ST_LONGFROMGEOHASH("10111000110001111001");
SELECT ST_LONGFROMGEOHASH("11111111111111111111");
SELECT ST_LONGFROMGEOHASH("99999999999999999999");
SELECT ST_LONGFROMGEOHASH(CAST("012" AS BINARY));
SELECT ST_LONGFROMGEOHASH(NULL);
SELECT ST_LONGFROMGEOHASH(null);
# Invalid characters and inputs
--echo # invalid characters and inputs
--error ER_WRONG_VALUE_FOR_TYPE
SELECT ST_LONGFROMGEOHASH("0123a45");
--error ER_WRONG_VALUE_FOR_TYPE
SELECT ST_LONGFROMGEOHASH("xyzi");
--error ER_WRONG_VALUE_FOR_TYPE
SELECT ST_LONGFROMGEOHASH("zyxLwv");
--error ER_WRONG_VALUE_FOR_TYPE
SELECT ST_LONGFROMGEOHASH("bcdjo");
--error ER_WRONG_VALUE_FOR_TYPE
SELECT ST_LONGFROMGEOHASH("zyx**wv");
--error ER_WRONG_VALUE_FOR_TYPE
SELECT ST_LONGFROMGEOHASH("1 2 3 4");
--error ER_WRONG_VALUE_FOR_TYPE
SELECT ST_LONGFROMGEOHASH("1''2345");
--error ER_WRONG_VALUE_FOR_TYPE
SELECT ST_LONGFROMGEOHASH("12.345");
--error ER_WRONG_VALUE_FOR_TYPE
SELECT ST_LONGFROMGEOHASH(" ");
--error ER_WRONG_VALUE_FOR_TYPE
SELECT ST_LONGFROMGEOHASH("NULL");
--error ER_WRONG_VALUE_FOR_TYPE
SELECT ST_LONGFROMGEOHASH("0a 0d");
--error ER_WRONG_VALUE_FOR_TYPE
SELECT ST_LONGFROMGEOHASH("-100");
--error ER_WRONG_VALUE_FOR_TYPE
SELECT ST_LONGFROMGEOHASH("");
--error ER_GIS_INVALID_DATA
SELECT ST_LONGFROMGEOHASH(9876543210);
--error ER_GIS_INVALID_DATA
SELECT ST_LONGFROMGEOHASH(0123456789);
--error ER_GIS_INVALID_DATA
SELECT ST_LONGFROMGEOHASH(1e1);
--error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
SELECT ST_LONGFROMGEOHASH();
--error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
SELECT ST_LONGFROMGEOHASH("123","456");
--error ER_PARSE_ERROR
SELECT ST_LONGFROMGEOHASH("123",);
--error ER_PARSE_ERROR
SELECT ST_LONGFROMGEOHASH(,"456");
--error ER_PARSE_ERROR
SELECT ST_LONGFROMGEOHASH(,);
--error ER_PARSE_ERROR
SELECT ST_LONGFROMGEOHASH("0123456"789);
--error ER_BAD_FIELD_ERROR
SELECT ST_LONGFROMGEOHASH(abcdef);
# Test geohashes that are long
--echo # very long geohash
SELECT ST_LONGFROMGEOHASH("0123456789bcdefghjkmnpqrstuvwxyz0123456789bcdefghjkm"
"npqrstuvwxyz0123456789bcdefghjkmnpqrstuvwxyz01234567"
"89bcdefghjkmnpqrstuvwxyz");
SELECT ST_LONGFROMGEOHASH("0123456789BCDEFGHJKMNPQRSTUVWXYZ0123456789BCDEFGHJKM"
"NPQRSTUVWXYZ0123456789BCDEFGHJKMNPQRSTUVWXYZ01234567"
"89BCDEFGHJKMNPQRSTUVWXYZ");
SELECT ST_LONGFROMGEOHASH("zyxwvutsrqpnmkjhgfedcb9876543210zyxwvutsrqpnmkjhgfed"
"cb9876543210zyxwvutsrqpnmkjhgfedcb9876543210zyxwvuts"
"rqpnmkjhgfedcb9876543210");
SELECT ST_LONGFROMGEOHASH("ZYXWVUTSRQPNMKJHGFEDCB9876543210ZYXWVUTSRQPNMKJHGFED"
"CB9876543210ZYXWVUTSRQPNMKJHGFEDCB9876543210ZYXWVUTS"
"RQPNMKJHGFEDCB9876543210");
# Table with different extreme values
CREATE TABLE geohashes (gid INT NOT NULL PRIMARY KEY, hash_value VARCHAR(255));
INSERT INTO geohashes VALUES
......@@ -39,6 +224,9 @@ INSERT INTO geohashes VALUES
(17, "wvetm3u23kr9r6663k31"),
(18, "e5t2p7sk291vpyb08pwu");
--echo # different random geohash values
SELECT ST_LONGFROMGEOHASH(hash_value) FROM geohashes;
#####################################################################
# ST_LATFROMGEOHASH()
#####################################################################
......@@ -613,5 +801,277 @@ SELECT ST_GEOHASH(ST_DIFFERENCE(ST_GEOMFROMTEXT('POINT(180 90)'),ST_GEOMFROMTEXT
--error ER_GIS_INVALID_DATA
SELECT ST_GEOHASH(ST_SYMDIFFERENCE(ST_GEOMFROMTEXT('POINT(180 90)'),ST_GEOMFROMTEXT('POINT(0 0)')),20);
#####################################################################
# Nested geohash functions
#####################################################################
--echo #=============================================================
--echo # ST_LONGFROMGEOHASH()
--echo #=============================================================
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(180,90,20));
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(180,-90,20));
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(-180,90,20));
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(-180,-90,20));
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(180,0,20));
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(-180,0,20));
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(-0,0,20));
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(0.10,90,20));
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(100,45,20));
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(179.999999,90,20));
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(-179.999999,0,20));
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(18*10,900/10,20));
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(100 10)'),10));
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(10 10)'),10));
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(-10 10)'),10));
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(1.000 10)'),10));
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(-1.000 10)'),10));
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(1.00101 90)'),20));
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(-1.00101 90)'),20));
SELECT ST_LONGFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(20 20)'),10));
--echo #=============================================================
--echo # ST_LATFROMGEOHASH()
--echo #=============================================================
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(180,90,20));
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(180,-90,20));
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(-180,90,20));
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(-180,-90,20));
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(0,90,20));
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(0,-90,20));
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(0,-0,20));
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(180,0.101,20));
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(100,45,20));
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(180,89.99999990,20));
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(0,89.999999,20));
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(18*10,900/10,20));
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(10 50)'),10));
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(10 10)'),10));
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(10 -10)'),10));
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(10 1.000)'),10));
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(10 -1.0000)'),10));
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(180 1.00101)'),20));
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(-100 -1.00101)'),20));
SELECT ST_LATFROMGEOHASH(ST_GEOHASH(ST_GEOMFROMTEXT('POINT(20 -20)'),10));
--echo #=============================================================
--echo # ST_GEOHASH()
--echo #=============================================================
SELECT ST_GEOHASH(ST_LONGFROMGEOHASH("zzzzzzzzzzzzzzzzzzzz"),ST_LATFROMGEOHASH("zzzzzzzzzzzzzzzzzzzz"),20);
SELECT ST_GEOHASH(ST_LONGFROMGEOHASH("00000000000000000000"),ST_LATFROMGEOHASH("00000000000000000000"),20);
SELECT ST_GEOHASH(ST_LONGFROMGEOHASH("zzzzzzzzzzzzzzzzzzzz"),ST_LATFROMGEOHASH("00000000000000000000"),20);
SELECT ST_GEOHASH(ST_LONGFROMGEOHASH("00000000000000000000"),ST_LATFROMGEOHASH("zzzzzzzzzzzzzzzzzzzz"),20);
SELECT ST_GEOHASH(ST_LONGFROMGEOHASH("pbpbpbpbpbpbpbpbpbpb"),ST_LATFROMGEOHASH("zzzzzzzzzzzzzzzzzzzz"),20);
SELECT ST_GEOHASH(ST_LONGFROMGEOHASH("zzzzzzzzzzzzzzzzzzzz"),ST_LATFROMGEOHASH("pbpbpbpbpbpbpbpbpbpb"),20);
SELECT ST_GEOHASH(ST_LONGFROMGEOHASH("zzzzzzzzzzzzzzzzzzzz"),ST_LATFROMGEOHASH("bpbpbpbpbpbpbpbpbpbp"),20);
SELECT ST_GEOHASH(ST_LONGFROMGEOHASH("bpbpbpbpbpbpbpbpbpbp"),ST_LATFROMGEOHASH("zzzzzzzzzzzzzzzzzzzz"),20);
SELECT ST_GEOHASH(ST_LONGFROMGEOHASH("bpbpbpbpbpbpbpbpbpbp"),ST_LATFROMGEOHASH("pbpbpbpbpbpbpbpbpbpb"),20);
#####################################################################
# Bug#19657725
#####################################################################
SELECT
ST_LONGFROMGEOHASH(
CAST("0123456789bcdefghjkmnpqrstuvwxyz0123456789BCDEFGHJKMNPQRSTUVWXYZ"
AS CHAR CHARACTER SET utf8) COLLATE utf8_persian_ci);
SELECT
ST_LONGFROMGEOHASH(
CAST("0123456789bcdefghjkmnpqrstuvwxyz0123456789BCDEFGHJKMNPQRSTUVWXYZ"
AS CHAR CHARACTER SET utf8) COLLATE utf8_czech_ci);
SELECT
ST_LONGFROMGEOHASH(
CAST("0123456789bcdefghjkmnpqrstuvwxyz0123456789BCDEFGHJKMNPQRSTUVWXYZ"
AS CHAR CHARACTER SET utf8) COLLATE utf8_unicode_ci);
SELECT
ST_LONGFROMGEOHASH(
CAST("0123456789bcdefghjkmnpqrstuvwxyz0123456789BCDEFGHJKMNPQRSTUVWXYZ"
AS CHAR CHARACTER SET utf8) COLLATE utf8_hungarian_ci);
SELECT
ST_LATFROMGEOHASH(
CAST("0123456789bcdefghjkmnpqrstuvwxyz0123456789BCDEFGHJKMNPQRSTUVWXYZ"
AS CHAR CHARACTER SET utf8) COLLATE utf8_persian_ci);
SELECT
ST_LATFROMGEOHASH(
CAST("0123456789bcdefghjkmnpqrstuvwxyz0123456789BCDEFGHJKMNPQRSTUVWXYZ"
AS CHAR CHARACTER SET utf8) COLLATE utf8_czech_ci);
SELECT
ST_LATFROMGEOHASH(
CAST("0123456789bcdefghjkmnpqrstuvwxyz0123456789BCDEFGHJKMNPQRSTUVWXYZ"
AS CHAR CHARACTER SET utf8) COLLATE utf8_unicode_ci);
SELECT
ST_LATFROMGEOHASH(
CAST("0123456789bcdefghjkmnpqrstuvwxyz0123456789BCDEFGHJKMNPQRSTUVWXYZ"
AS CHAR CHARACTER SET utf8) COLLATE utf8_hungarian_ci);
#####################################################################
# Bug#19383904
#####################################################################
# This table is for testing functions with DOUBLE values. Literals like 10.2 are
# recognized as DECIMAL.
CREATE TABLE t1 (val DOUBLE);
INSERT INTO t1 (val) VALUES (12.2);
SELECT val INTO @double FROM t1;
DROP TABLE t1;
SET @null = NULL;
SET @geohash = "01bbgcee";
PREPARE stmt FROM "SELECT ST_LONGFROMGEOHASH(?)";
EXECUTE stmt USING @geohash;
DEALLOCATE PREPARE stmt;
SELECT ST_LONGFROMGEOHASH(@geohash);
SELECT ST_LONGFROMGEOHASH(@null);
PREPARE stmt FROM "SELECT ST_LATFROMGEOHASH(?)";
EXECUTE stmt USING @geohash;
DEALLOCATE PREPARE stmt;
SELECT ST_LATFROMGEOHASH(@geohash);
SELECT ST_LATFROMGEOHASH(@null);
SET @maxlen = 3;
PREPARE stmt FROM "SELECT ST_GeoHash(POINT(10, 10), ?)";
EXECUTE stmt USING @maxlen;
DEALLOCATE PREPARE stmt;
SELECT ST_GeoHash(POINT(10, 10), @maxlen);
SELECT ST_GeoHash(POINT(10, 10), @null);
SET @point = POINT(10, 10);
PREPARE stmt FROM "SELECT ST_GeoHash(?, 10)";
EXECUTE stmt USING @point;
DEALLOCATE PREPARE stmt;
SELECT ST_GeoHash(@point, 10);
SELECT ST_GeoHash(@null, 10);
SET @long = 22.0311;
PREPARE stmt FROM "SELECT ST_GeoHash(?, 10, 10)";
EXECUTE stmt USING @long;
DEALLOCATE PREPARE stmt;
SELECT ST_GeoHash(@long, 10, 10);
SELECT ST_GeoHash(@null, 10, 10);
SET @lat = -54.123;
PREPARE stmt FROM "SELECT ST_GeoHash(10, ?, 10)";
EXECUTE stmt USING @lat;
DEALLOCATE PREPARE stmt;
SELECT ST_GeoHash(10, @lat, 10);
SELECT ST_GeoHash(10, @null, 10);
PREPARE stmt FROM "SELECT ST_GeoHash(10, 10, ?)";
EXECUTE stmt USING @maxlen;
DEALLOCATE PREPARE stmt;
SELECT ST_GeoHash(10, 10, @maxlen);
SELECT ST_GeoHash(@double, @double, 10);
--error ER_GIS_INVALID_DATA
SELECT ST_GeoHash(POINT(10, 10), @double);
#####################################################################
# Bug#20293609
#####################################################################
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a VARCHAR(255));
INSERT INTO t1 (a) VALUES (' ');
--error ER_WRONG_VALUE_FOR_TYPE
SELECT ST_LONGFROMGEOHASH(a) FROM t1;
--error ER_WRONG_VALUE_FOR_TYPE
SELECT ST_LATFROMGEOHASH(a) FROM t1;
DELETE FROM t1;
INSERT INTO t1 VALUES ('swpwwwwww'), ('guqtjvooguqtjvoo');
--error ER_WRONG_VALUE_FOR_TYPE
SELECT ST_LONGFROMGEOHASH(a) FROM t1;
--error ER_WRONG_VALUE_FOR_TYPE
SELECT ST_LATFROMGEOHASH(a) FROM t1;
--echo # Clean up
DROP TABLE geohashes;
DROP TABLE t1;
--echo #
--echo # Bug#22838668 CRASH IN ITEM_FUNC_LATLONGFROMGEOHASH::VAL_REAL
--echo # WITH BAD PARAMETERS
--echo #
--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION
DO ST_Disjoint(
POLYGON(
LINESTRING(POINT(1, 1))
),
ST_LatFromGeoHash(ExtractValue(1, NULL))
);
--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION
DO ST_Disjoint(
POLYGON(
LINESTRING(POINT(1, 1))
),
ST_LongFromGeoHash(ExtractValue(1, NULL))
);
--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION
DO ST_Disjoint(
POLYGON(
LINESTRING(POINT(1, 1))
),
ST_LatFromGeoHash(UpdateXML(1, NULL, NULL))
);
--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION
DO ST_Disjoint(
POLYGON(
LINESTRING(POINT(1, 1))
),
ST_LongFromGeoHash(UpdateXML(1, NULL, NULL))
);
......@@ -2672,7 +2672,7 @@ String *Item_func_geohash::val_str(String *str)
{
DBUG_ASSERT(fixed());
double latitude, longitude;
uint geohash_length;
int geohash_length;
Item* length_field;
null_value= 1;
......@@ -2683,7 +2683,7 @@ String *Item_func_geohash::val_str(String *str)
String tmp;
String *wkb= args[0]->val_str(&tmp);
if (args[0]->null_value || args[1]->null_value)
if (args[0]->null_value)
return 0;
length_field= args[1];
......@@ -2698,7 +2698,7 @@ String *Item_func_geohash::val_str(String *str)
}
else
{
if (args[0]->null_value || args[1]->null_value || args[2]->null_value)
if (args[0]->null_value || args[1]->null_value)
return 0;
if (is_invalid_longitude_field(args[0]->field_type()) ||
......@@ -2710,6 +2710,10 @@ String *Item_func_geohash::val_str(String *str)
longitude= args[0]->val_real();
latitude= args[1]->val_real();
if (args[0]->null_value || args[1]->null_value)
return 0;
length_field= args[2];
}
......@@ -2734,6 +2738,9 @@ String *Item_func_geohash::val_str(String *str)
}
geohash_length= static_cast<uint>(length_field->val_int());
if (length_field->null_value)
geohash_length= MAX_GEOHASH_LENGTH;
if (geohash_length <= MIN_GEOHASH_LENGTH ||
geohash_length > MAX_GEOHASH_LENGTH)
{
......@@ -2760,7 +2767,9 @@ bool Item_func_geohash::is_invalid_length_field(enum_field_types field_type)
{
case MYSQL_TYPE_LONG:
case MYSQL_TYPE_NULL:
case MYSQL_TYPE_LONGLONG:
case MYSQL_TYPE_VARCHAR:
case MYSQL_TYPE_LONG_BLOB:
return false;
default:
return true;
......@@ -2775,6 +2784,9 @@ bool Item_func_geohash::is_invalid_longitude_field(enum_field_types field_type)
case MYSQL_TYPE_LONG:
case MYSQL_TYPE_VARCHAR:
case MYSQL_TYPE_NEWDECIMAL:
case MYSQL_TYPE_GEOMETRY:
case MYSQL_TYPE_DOUBLE:
case MYSQL_TYPE_LONG_BLOB:
return false;
default:
return true;
......@@ -3008,6 +3020,8 @@ bool Item_func_latlongfromgeohash::is_invalid_geohash_field(
{
case MYSQL_TYPE_NULL:
case MYSQL_TYPE_VARCHAR:
case MYSQL_TYPE_LONG_BLOB:
case MYSQL_TYPE_GEOMETRY:
return false;
default:
return true;
......@@ -3515,6 +3529,23 @@ class Create_func_latfromgeohash : public Create_func_arg1
virtual ~Create_func_latfromgeohash() = default;
};
class Create_func_longfromgeohash : public Create_func_arg1
{
public:
Item *create_1_arg(THD *thd, Item *arg1) override
{
return new (thd->mem_root) Item_func_longfromgeohash(thd, arg1);
}
static Create_func_longfromgeohash s_singleton;
protected:
Create_func_longfromgeohash() = default;
virtual ~Create_func_longfromgeohash() = default;
};
class Create_func_endpoint : public Create_func_arg1
{
public:
......@@ -4369,6 +4400,7 @@ Create_func_distance Create_func_distance::s_singleton;
Create_func_distance_sphere Create_func_distance_sphere::s_singleton;
Create_func_geohash Create_func_geohash::s_singleton;
Create_func_latfromgeohash Create_func_latfromgeohash ::s_singleton;
Create_func_longfromgeohash Create_func_longfromgeohash ::s_singleton;
Create_func_endpoint Create_func_endpoint::s_singleton;
Create_func_envelope Create_func_envelope::s_singleton;
Create_func_equals Create_func_equals::s_singleton;
......@@ -4494,6 +4526,7 @@ static Native_func_registry func_array_geom[] =
{ { STRING_WITH_LEN("POLYGONFROMWKB") }, GEOM_BUILDER(Create_func_geometry_from_wkb)},
{ { STRING_WITH_LEN("GEOHASH") }, GEOM_BUILDER(Create_func_geohash)},
{ { STRING_WITH_LEN("LATFROMGEOHASH") }, GEOM_BUILDER(Create_func_latfromgeohash)},
{ { STRING_WITH_LEN("LONGFROMGEOHASH") }, GEOM_BUILDER(Create_func_longfromgeohash)},
{ { STRING_WITH_LEN("SRID") }, GEOM_BUILDER(Create_func_srid)},
{ { STRING_WITH_LEN("ST_AREA") }, GEOM_BUILDER(Create_func_area)},
{ { STRING_WITH_LEN("STARTPOINT") }, GEOM_BUILDER(Create_func_startpoint)},
......@@ -4577,6 +4610,7 @@ static Native_func_registry func_array_geom[] =
{ { STRING_WITH_LEN("ST_DISTANCE_SPHERE") }, GEOM_BUILDER(Create_func_distance_sphere)},
{ { STRING_WITH_LEN("ST_GEOHASH") }, GEOM_BUILDER(Create_func_geohash)},
{ { STRING_WITH_LEN("ST_LATFROMGEOHASH") }, GEOM_BUILDER(Create_func_latfromgeohash)},
{ { STRING_WITH_LEN("ST_LONGFROMGEOHASH") }, GEOM_BUILDER(Create_func_longfromgeohash)},
{ { STRING_WITH_LEN("TOUCHES") }, GEOM_BUILDER(Create_func_touches)},
{ { STRING_WITH_LEN("WITHIN") }, GEOM_BUILDER(Create_func_within)},
{ { STRING_WITH_LEN("X") }, GEOM_BUILDER(Create_func_x)},
......
......@@ -1285,6 +1285,21 @@ class Item_func_latfromgeohash: public Item_func_latlongfromgeohash
};
class Item_func_longfromgeohash: public Item_func_latlongfromgeohash
{
public:
Item_func_longfromgeohash(THD *thd, Item *a)
:Item_func_latlongfromgeohash(thd, a, true) {}
LEX_CSTRING func_name_cstring() const override
{
static LEX_CSTRING name= {STRING_WITH_LEN("st_longfromgeohash") };
return name;
}
Item *do_get_copy(THD *thd) const override
{ return get_item_copy<Item_func_longfromgeohash>(thd, this); }
};
class Item_func_pointonsurface: public Item_geometry_func_args_geometry
{
String tmp_value;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment