1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817
|
<?xml version="1.0" encoding="utf-8"?>
<test>
<name>JSON attributes</name>
<requires>
<sphinxql_keep_null/>
</requires>
<config>
common
{
on_json_attr_error = ignore_attr
json_autoconv_numbers = 1
}
indexer
{
mem_limit = 16M
}
searchd
{
<searchd_settings/>
workers = threads
collation_libc_locale = C
collation_server = binary
}
source test
{
type = mysql
<sql_settings/>
sql_query = select * from test_table
sql_attr_uint = gid
sql_attr_json = j
}
index test
{
source = test
path = <data_path/>/test
}
source src1
{
type = mysql
<sql_settings/>
sql_query = select *, 1 as gid, 'dummy' as title from json_table where id%3=1
sql_attr_uint = gid
sql_attr_json = j
}
source src2
{
type = mysql
<sql_settings/>
sql_query = select *, 2 as gid, 'dummy' as title from json_table where id%3=2
sql_attr_uint = gid
sql_attr_json = j
}
source src3
{
type = mysql
<sql_settings/>
sql_query = select *, 3 as gid, 'dummy' as title from json_table where id%3=0
sql_attr_uint = gid
sql_attr_json = j
}
index i1
{
source = src1
path = <data_path/>/i1
}
index i2
{
source = src2
path = <data_path/>/i2
}
index i3
{
source = src3
path = <data_path/>/i3
}
index loc
{
type = distributed
local = i1
local = i2
}
index dist
{
type = distributed
agent = <my_address/>:i1
agent = <my_address/>:i2
}
index dist1
{
type = distributed
agent = <my_address/>:i1
agent = <my_address/>:i2
local = i3
}
index loc1
{
type = distributed
local = i1
agent = <my_address/>:i2
}
index loc_field
{
type = distributed
local = test
agent = <my_address/>:i2
}
index dist_field
{
type = distributed
local = <my_address/>:i2
agent = <my_address/>:test
}
source src_case
{
type = mysql
<sql_settings/>
sql_query = select *, 11 as gid, 'dummy' as title from json_case
sql_attr_uint = gid
sql_attr_json = j
}
index json_case
{
source = src_case
path = <data_path/>/case
}
index rt
{
type = rt
path = <data_path/>/rt
rt_field = title
rt_attr_json = data
}
source json_attr
{
type = mysql
<sql_settings/>
sql_query = SELECT * from json_attr
sql_attr_json = json1
}
index json_attr
{
source = json_attr
path=<data_path/>/json_attr
}
index dist_str
{
type = distributed
agent = <my_address/>:json_attr
}
index rt1
{
type = rt
path = <data_path/>/rt1
rt_field = title
rt_attr_string = s1
rt_attr_json = j1
}
source json_arrays
{
type = mysql
<sql_settings/>
sql_query = SELECT * from json_arrays
sql_attr_json = j
}
index arrays
{
source = json_arrays
path=<data_path/>/json_arrays
}
source json_objects
{
type = mysql
<sql_settings/>
sql_query = SELECT * from json_objects
sql_attr_json = j
}
index objects
{
source = json_objects
path=<data_path/>/json_objects
}
index dist_case
{
type = distributed
agent = <my_address/>:json_case
}
source json_inplace
{
type = mysql
<sql_settings/>
sql_query = SELECT * from json_inplace
sql_attr_uint = gid
sql_attr_json = j
}
index json_inplace
{
source = json_inplace
path=<data_path/>/json_inplace
}
index json_inplace_rt
{
type = rt
path = <data_path/>/json_inplace_rt
rt_field = title
rt_attr_uint = gid
rt_attr_json = j
}
index json_search
{
type = rt
path = <data_path/>/json_search
rt_attr_json = j
rt_attr_string = title
rt_field = text
}
index json_order
{
type = rt
path = <data_path/>/json_order
rt_attr_json = j
rt_field = text
}
index json_toplevel
{
type = rt
path = <data_path/>/json_toplevel
rt_attr_json = j
rt_field = text
}
source json_up1
{
type = mysql
<sql_settings/>
sql_query = SELECT 1, 'test me' t, '{"R158S": 901, "rom": 202, "t1":"A", "t2":"AB", T1:"C"}' j
sql_attr_json = j
}
index json_up1
{
source = json_up1
path=<data_path/>/json_up1
}
source json_up2
{
type = mysql
<sql_settings/>
sql_query = SELECT 100, 'test me' t, '{"R158S": 100, "rom": 303, "t1":"B", "t2":"BC", T1:"D"}' j
sql_attr_json = j
}
index json_up2
{
source = json_up2
path=<data_path/>/json_up2
}
index dist_up
{
type = distributed
agent = <my_address/>:json_up1
agent = <my_address/>:json_up2
}
index json_remap
{
type = rt
path = <data_path/>/json_remap
rt_attr_json = j1
rt_attr_json = j2
rt_field = text
}
</config>
<db_create>
CREATE TABLE `test_table` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`gid` int(11) NOT NULL,
`title` varchar(255) NOT NULL,
`j` varchar(8192) NOT NULL,
PRIMARY KEY (`id`)
);
</db_create>
<db_drop>DROP TABLE IF EXISTS `test_table`;</db_drop>
<db_insert>
INSERT INTO `test_table` VALUES
(1,1,'test one','{"name":"Alice","uid":123}'),
(2,1,'test two','{"name":"Bob","uid":234,"gid":12}'),
(3,2,'another doc','{"name":"Charlie","uid":345}'),
(4,2,'doc number four','{"name":"Damon","uid":456,"gid":23}'),
(5,3,'numeric fixup','{"12":345, "34":"567"}'),
(6,3,'numeric fixup contd','{"12":"346", "179":"971"}'),
(7,3,'strings over 256 bytes','{"long":"
You can run on for a long time
Run on for a long time
Run on for a long time
Sooner or later God\'ll cut you down
Sooner or later God\'ll cut you down
Go tell that long tongue liar
Go and tell that midnight rider
Tell the rambler, the gambler, the back biter
Tell \'em that God\'s gonna cut \'em down
Tell \'em that God\'s gonna cut \'em down
", "short":"ohai"}'),
(8,3,'stringvector test','{sv:["one","two","three"],gid:315}'),
(9,3,'empty','{}'),
(10,3,'empty v2',''),
(11,3,'all the bitnesses','{"t1":123456789,"t2":-123456789,
"t3":3123456789,"t4":-3123456789,
"t5":9876543210,"t6":-9876543210}'),
(12,3,'stringvector vs longer strings','{sv:["
Mary had a little lamb, whose fleece was white as snow.
And everywhere that Mary went, the lamb was sure to go.
It followed her to school one day which was against the rules.
It made the children laugh and play, to see a lamb at school.
And so the teacher turned it out, but still it lingered near.",
"another world, another time, the age of wonders"],
"gid":316}'),
(13,3,'long numbers vs string to numeric fixup','{
i1:"123",
i2:"-123",
i3:"18446744073709551615",
i4:"-18446744073709551615",
i5:"9223372036854775807",
i6:"9223372036854775808",
i7:"9223372036854775809",
i8:"-9223372036854775807",
i9:"-9223372036854775808",
i10:"-9223372036854775809",
i11:"123abc",
i12:"-123abc",
f1:"3.15",
f2:"16777217.123"}'),
(14,3,'floats','{
f1:3.15,
f2:-7.40,
f3:65536.7,
f4:16777217.123}'),
(15,3,'invalid json','{ this is not valid }'),
(16,4,'unescaping','{nick:"One\nTwo"}'),
(17,4,'unescaping','{nick:"One\\nTwo"}'),
(18,4,'unescaping','{nick:"One
Two"}')
</db_insert>
<db_create>CREATE TABLE `json_table` ( `id` int(11) NOT NULL, `j` varchar(8192) NOT NULL );</db_create>
<db_drop>DROP TABLE IF EXISTS `json_table`;</db_drop>
<db_insert>
INSERT INTO `json_table` VALUES
(1,'{"uid":123}'),
(2,'{"uid":234}'),
(3,'{"uid":345}'),
(4,'{"uid":456}'),
(5,'{"uid":567}'),
(6,'{"uid":678}'),
(7,'{"uid":123}'),
(8,'{"uid":567}'),
(9,'{"uid":345}'),
( 100, '' )
</db_insert>
<db_create>CREATE TABLE `json_case` ( `id` int(11) NOT NULL, `j` varchar(8192) NOT NULL );</db_create>
<db_drop>DROP TABLE IF EXISTS `json_case`;</db_drop>
<db_insert>
INSERT INTO `json_case` VALUES
(1,'{"Attr":123, "aTTr":12, "Str":"nope", "STR":"yep" }'),
(2,'{"Attr":23, "Str":"nope", "STR":"yep2" }'),
(3,'{"Attr":123, "aTTr":12, "STR":"yep" }'),
(4,'{"Attr":123, "aTTr":212, "Str":"nope11" }'),
(5,'{"Attr":12, "aTTr":12 }'),
(6,'{ "Str":"nope", "STR":"yep" }'),
(7,'{ "aTTr":212, "STR":"yep2" }'),
(8,'{"Attr":12, "Str":"nope11" }')
</db_insert>
<db_create>CREATE TABLE json_attr ( id INTEGER NOT NULL, gid INTEGER NOT NULL, json1 VARCHAR(255) NOT NULL )</db_create>
<db_drop>DROP TABLE IF EXISTS `json_attr`;</db_drop>
<db_insert>
INSERT INTO json_attr ( id, gid, json1 ) VALUES
( 123, 1, '{"username":"Alice","year":2000,"floatkey": 1.01}' ),
( 234, 1, '{"username":"Bob","year":2001,"floatkey": 2.22}' ),
( 345, 2, '{"username":"Charlie","year":2002,"floatkey": 3.00}' ),
( 456, 2, '{"username":"Damon","year":2003,"floatkey": 4.44}' )
</db_insert>
<db_create>CREATE TABLE json_arrays ( id INTEGER NOT NULL, gid INTEGER NOT NULL, j VARCHAR(255) NOT NULL )</db_create>
<db_drop>DROP TABLE IF EXISTS `json_arrays`;</db_drop>
<db_insert>
INSERT INTO json_arrays ( id, gid, j ) VALUES
( 123, 1, '{"a":[1,2,3,4], "t":["t1", "t2", "t3"]}' ),
( 234, 1, '{"a":[2,3,4,5], "t":["t2", "t3", "t4"]}' ),
( 345, 2, '{"a":[3,4,5,1], "t":["t3", "t4", "t5"]}' ),
( 456, 2, '{"a":["4","5","6","2"], "t":["t4", "t5", "t6"]}' )
</db_insert>
<db_create>CREATE TABLE json_objects ( id INTEGER NOT NULL, gid INTEGER NOT NULL, j VARCHAR(255) NOT NULL )</db_create>
<db_drop>DROP TABLE IF EXISTS `json_objects`;</db_drop>
<db_insert>
INSERT INTO json_objects ( id, gid, j ) VALUES
(1,1,'[6,[6,[6,[6,6.0]]]]'),
(2,1,'[1, 2, 3.0, 1000000000000,["a","b","c"],{"a":"b"}]'),
(3,1,'{"a":"tag","b":"another tag"}'),
(4,1,'[1,2,3,[4,5,6,[7,8]]]'),
(5,1,'{"MixedCase":"passed"}'),
(6,2,'[1,2,3,[4,5,[6]],7,"8",{a:"b"},{},[6,6,6.0,6]]'),
(7,2,'[1,"x",{"y":"3","assoc":{"a1":6,"a2":5,"a3":"tag1", "a4":{"b1":1,"b2":2}}}, "123"]'),
(8,2,'{"a":{"c":"d"},"b":"c","e":6}'),
(9,2,'[false, true, null, "15\\u00f8C"]'),
(10,3,'{key1:{key2:{key3:"value"}}}'),
(11,4,'{"1234":1,"123":2,"1234a":3}'),
(12,4,'{}'),
(13,4,'[]'),
(14,4,'')
</db_insert>
<db_create>CREATE TABLE json_inplace ( id INTEGER NOT NULL, gid INTEGER NOT NULL, title VARCHAR(255), j VARCHAR(255) NOT NULL )</db_create>
<db_drop>DROP TABLE IF EXISTS `json_inplace`;</db_drop>
<db_insert>
INSERT INTO json_inplace ( id, gid, title, j ) VALUES
( 1,1,'','{"a":[1,2,3,4],"f":[1.0,3.0,2.0]}'),
( 2,1,'','{"a":[2,3,4,5],"f":[2.0,4.0,3.0]}'),
( 3,2,'','{"a":"tag1","b":"tag2"}'),
( 4,3,'','{"a":1,"c":2}');
</db_insert>
<queries>
<!-- json via API -->
<query index="loc" select="*, @count" groupattr="j.uid" sortmode="extended" sortby="id asc" groupsort="id asc"/>
<query index="loc1" select="*, @count" groupattr="j.uid" sortmode="extended" sortby="id asc" groupsort="id asc"/>
<query index="dist" select="*, @count" groupattr="j.uid" sortmode="extended" sortby="id asc" groupsort="id asc"/>
<query index="dist1" select="*, @count" groupattr="j.uid" sortmode="extended" sortby="id asc" groupsort="id asc"/>
<!-- json.field via API -->
<query index="loc_field" select="bigint ( id ), j.uid, j.name" filter="j.uid" filter_range="249 1000"/>
<query index="loc_field" select="bigint ( id ), j.uid, j.name" sortmode="extended" sortby="j.name asc, j.gid desc"/>
<query index="dist_field" select="bigint ( id ), j.name, j.uid" sortmode="extended" sortby="j.name desc, j.gid asc"/>
<query index="dist_field" select="bigint ( id ), j.name, j.34, j.179, j.uid, j.sv, j.t6, j. f2, j.f1"/>
<!-- string filter via distributed index -->
<query index="dist_str" filter="json1.username" filter_str="Alice"/>
<query index="dist_str" filter="json1.username" filter_str="Damon"/>
<!-- check json quoting via API -->
<query index="objects" select="j, j.key1.key2.key3" filter="j.key1.key2.key3" filter_str="value"/>
</queries>
<sphqueries>
<!-- group by vs distributed index -->
<sphinxql>select *, count(*) from loc group by j.uid order by id asc</sphinxql>
<sphinxql>select *, count(*) from loc1 group by j.uid order by id asc</sphinxql>
<sphinxql>select *, count(*) from dist group by j.uid order by id asc</sphinxql>
<sphinxql>select *, count(*) from dist1 group by j.uid order by id asc</sphinxql>
<!-- query that cause crash -->
<sphinxql>select * from count() loc group by j.uid</sphinxql>
<sphinxql>select * from test</sphinxql>
<sphinxql>select * from test where j.uid>200</sphinxql>
<sphinxql>select * from test where j.t1>0</sphinxql>
<sphinxql>select * from test where j.t2<0</sphinxql>
<sphinxql>select * from test where j.t5>0</sphinxql>
<sphinxql>select * from test where j.t6<0</sphinxql>
<sphinxql>select * from test where j.name='Alice'</sphinxql>
<sphinxql>select * from test where j.name='alice'</sphinxql>
<sphinxql>select * from test where j.short='ohai'</sphinxql>
<sphinxql>select * from test where j.gid=315</sphinxql>
<sphinxql>select * from test where j.gid='315'</sphinxql>
<sphinxql>select * from test where j.gid>315</sphinxql>
<sphinxql>select * from test where j.gid=12</sphinxql>
<sphinxql>select * from test where id=13</sphinxql>
<sphinxql>select * from test where id=14</sphinxql>
<!-- ORDER BY, NULL(able) values are presented first if you do ORDER BY ... ASC and last if you do ORDER BY ... DESC -->
<sphinxql>select id, j from test order by j.name asc, j.gid desc</sphinxql>
<sphinxql>select id, j from test order by j.name desc, j.gid asc</sphinxql>
<!-- json.field via SphinxQL -->
<sphinxql>select id, j.uid, j.name from loc_field where j.uid>250</sphinxql>
<sphinxql>select id, j.uid, j.name from loc_field order by j.name asc, j.gid desc</sphinxql>
<sphinxql>select id, j.name, j.uid from dist_field order by j.name desc, j.gid asc</sphinxql>
<sphinxql>select id, j.name, j.34, j.179, j.uid, j.sv, j.t6, j. f2, j.f1 from dist_field </sphinxql>
<!-- json.field case -->
<sphinxql>select id, j.Attr as j1, j.aTTr j2, j.Str as j3, j.STR j4 from json_case</sphinxql>
<sphinxql>select id, j.Attr, j.aTTr, j.Str, j.STR from json_case where j.Attr>100</sphinxql>
<sphinxql>select id, j.Attr, j.aTTr, j.Str, j.STR from json_case where j.aTTr<100</sphinxql>
<sphinxql>select id, j.Attr, j.aTTr, j.Str, j.STR from json_case where j.Str='nope'</sphinxql>
<sphinxql>select id, j.Attr, j.aTTr, j.Str, j.STR from json_case where j.STR='yep'</sphinxql>
<sphinxql>select id, count(*) c, j.Attr, j.aTTr, j.Str, j.STR from json_case group by j.Attr</sphinxql>
<sphinxql>select id, count(*) c, j.Attr, j.aTTr, j.Str, j.STR from json_case group by j.aTTr</sphinxql>
<sphinxql>select id, count(*) c, j.Attr, j.aTTr, j.Str, j.STR from json_case group by j.Str</sphinxql>
<sphinxql>select id, count(*) c, j.Attr, j.aTTr, j.Str, j.STR from json_case group by j.STR</sphinxql>
<sphinxql>select id, j.Attr, j.aTTr, j.Str, j.STR from json_case order by j.Attr asc, id desc</sphinxql>
<sphinxql>select id, j.Attr, j.aTTr, j.Str, j.STR from json_case order by j.aTTr desc, id desc</sphinxql>
<sphinxql>select id, j.Attr, j.aTTr, j.Str, j.STR from json_case order by j.Str asc, id desc</sphinxql>
<sphinxql>select id, j.Attr, j.aTTr, j.Str, j.STR from json_case order by j.STR desc, id desc</sphinxql>
<!-- json vs rt -->
<sphinxql>insert into rt (id, title, data) values (1, 'title1','{attr1:10, attr2:"test1"}')</sphinxql>
<sphinxql>insert into rt (id, title, data) values (2, 'title2','{attr1:20, attr2:"test2"}')</sphinxql>
<sphinxql>insert into rt (id, title, data) values (3, 'title3','{attr1:30, attr2:"test3"}')</sphinxql>
<sphinxql>select * from rt</sphinxql>
<sphinxql>select * from rt where data.attr1=20</sphinxql>
<sphinxql>select * from rt group by data.attr1</sphinxql>
<sphinxql>replace into rt (id, data) values (3, '{attr1:100, attr2:"replaced", new_attr:"text"}')</sphinxql>
<sphinxql>select * from rt</sphinxql>
<sphinxql>select * from rt group by data.new_attr</sphinxql>
<sphinxql>select data.attr2 from rt group by data.new_attr</sphinxql>
<!-- quoting check -->
<sphinxql>select * from json_attr</sphinxql>
<sphinxql>select json1.username from json_attr where id=123</sphinxql>
<sphinxql>select json1.year from json_attr where id=123</sphinxql>
<!-- floats check -->
<sphinxql>select * from json_attr where json1.floatkey>1.234</sphinxql>
<sphinxql>select * from json_attr where json1.floatkey between 1 and 3</sphinxql>
<sphinxql>select * from json_attr where json1.floatkey between 1.01 and 3.0</sphinxql>
<sphinxql>select * from json_attr where json1.floatkey between 1.01 and 1.02</sphinxql>
<sphinxql>select * from json_attr where json1.floatkey>2.22</sphinxql>
<sphinxql>select * from json_attr where json1.floatkey>=2.22</sphinxql>
<!-- json in multiple -->
<sphinxql>select *, groupby(), count(*) from test group by gid, j.t1, j.gid</sphinxql>
<!-- type conversion -->
<sphinxql>select double(json1.year) from json_attr</sphinxql>
<sphinxql>select double(json1.floatkey) from json_attr</sphinxql>
<sphinxql>select sum(integer(json1.year)) from json_attr</sphinxql>
<sphinxql>select sum(double(json1.floatkey)) from json_attr</sphinxql>
<sphinxql>select avg(double(json1.floatkey)) from json_attr</sphinxql>
<sphinxql>select avg(integer(json1.floatkey)) from json_attr</sphinxql>
<sphinxql>select min(bigint(json1.floatkey)) from json_attr</sphinxql>
<sphinxql>select min(bigint(json1.year)) from json_attr</sphinxql>
<sphinxql>select max(double(json1.floatkey)) from json_attr</sphinxql>
<sphinxql>select max(integer(json1.floatkey)) from json_attr</sphinxql>
<sphinxql>select double(json1.year) as year from json_attr where year>=2002.0</sphinxql>
<sphinxql>select integer(json1.floatkey) as floatkey from json_attr where floatkey>=2</sphinxql>
<!-- multiple conditions -->
<sphinxql>select * from json_attr where json1.year=2000 and json1.floatkey>=1.01</sphinxql>
<sphinxql>select * from json_attr where json1.year=2000 and json1.floatkey>=1.01 and json1.username='Alice'</sphinxql>
<!-- regression json missed on RT insert -->
<sphinxql>insert into rt1 (id, title) values (100, 'title1' )</sphinxql>
<sphinxql>select * from rt1 where id=100</sphinxql>
<!-- filtering integers using floating point precision -->
<sphinxql>select * from json_attr where json1.year>=2001 and json1.year<2003</sphinxql>
<sphinxql>select * from json_attr where json1.year>=2001.0 and json1.year<2003</sphinxql>
<sphinxql>select * from json_attr where json1.year>=2001.0 and json1.year<2003.0</sphinxql>
<sphinxql>select * from json_attr where json1.year>=2000.0001 and json1.year<2003.0001</sphinxql>
<sphinxql>select * from json_attr where json1.year>=2000.000001 and json1.year<2003.000001</sphinxql>
<!-- string filter via distributed index -->
<sphinxql>select * from dist_str where json1.username='Alice'</sphinxql>
<sphinxql>select * from dist_str where json1.username='Damon'</sphinxql>
<!-- stirng filter vs escaped strings -->
<sphinxql>select * from test where j.nick='One\nTwo'</sphinxql>
<sphinxql>select * from test where j.nick='one\ntwo'</sphinxql>
<sphinxql>select * from test where j.nick='One
Two'</sphinxql>
<!-- array functions -->
<sphinxql>select * from arrays</sphinxql>
<sphinxql>select j.a[0] from arrays</sphinxql>
<sphinxql>select j.a[2] from arrays where j.a[2]>2</sphinxql>
<sphinxql>select j.a[2] from arrays order by j.a[2] desc</sphinxql>
<sphinxql>select in(j.a,4,6) as p from arrays where p=1</sphinxql>
<sphinxql>select j.t[2] from arrays</sphinxql>
<sphinxql>select j.t[2] from arrays where j.t[2]='t3'</sphinxql>
<sphinxql>select j.t[2] from arrays order by j.t[2] desc</sphinxql>
<sphinxql>select j.t, in(j.t,'t4','t6') as p from arrays where p=1</sphinxql>
<sphinxql>select j.a[-1], j.t[-1], j.a[5], j.t[5] from arrays</sphinxql>
<sphinxql>select least(j.a), greatest(j.a), least(j.t), greatest(j.t) from arrays</sphinxql>
<!-- fulljson subscript and null filter -->
<sphinxql>select j from objects</sphinxql>
<sphinxql>select j[0] from objects where j[0] is not null</sphinxql>
<sphinxql>select j[1] from objects where j[1] is not null</sphinxql>
<sphinxql>select j[2] from objects where j[2] is not null</sphinxql>
<sphinxql>select j[2]['assoc'].a4 from objects where j[2]['assoc'].a4 is not null</sphinxql>
<sphinxql>select j['MixedCase'], j['mixedcase'] from objects where j.MixedCase is not null</sphinxql>
<sphinxql>select j[1][1][1][1] from objects where j[1][1][1][1] is not null</sphinxql>
<sphinxql>select j.a[j.b] from objects where j.a[j.b] is not null</sphinxql>
<sphinxql>select j[id] from objects where j[id] is not null</sphinxql>
<sphinxql>select j[2*id-3] from objects where j[2*id-3] is not null</sphinxql>
<!-- group by array elements and containers -->
<sphinxql>select j.a from objects group by j.a</sphinxql>
<sphinxql>select j[0] from objects group by j[0]</sphinxql>
<sphinxql>select j[1] from objects group by j[1]</sphinxql>
<!-- func_in for arrays and array elements -->
<sphinxql>select j, in(j,6) as p from objects where p=1</sphinxql>
<sphinxql>select j.a, in(j.a,'tag') as p from objects where p=1</sphinxql>
<sphinxql>select j[0], in(j[0],1,2) as p from objects where p=1</sphinxql>
<sphinxql>select j[2], in(j[2],2,3) as p from objects where p=1</sphinxql>
<sphinxql>select j[3][3], in(j[3][3],7) as p from objects where p=1</sphinxql>
<!-- numeric fields -->
<sphinxql>select j.1234, j.123, .1234, .123 from objects where j.1234 is not null</sphinxql>
<sphinxql>select j.1234, j.1234a from objects where j.1234a is not null</sphinxql>
<sphinxql>select j 0.1234 as error from objects</sphinxql>
<!-- aliases and null filter -->
<sphinxql>select j from objects where j is not null</sphinxql>
<sphinxql>select j as p from objects where p is not null</sphinxql>
<sphinxql>select j[2]['assoc'].a4 as p from objects where p is not null</sphinxql>
<!-- length function -->
<sphinxql>select length(j) from objects</sphinxql>
<sphinxql>select length(j[0]) from objects</sphinxql>
<sphinxql>select length(j.a) from objects</sphinxql>
<!-- mixed case for distributed index -->
<sphinxql>select j.str from dist_case where j.str is not null order by j.str asc</sphinxql>
<sphinxql>select j.Str from dist_case where j.Str is not null order by j.Str asc</sphinxql>
<sphinxql>select j.STR from dist_case where j.STR is not null order by j.STR asc</sphinxql>
<!-- sort by aliased attribute for local and distributed indexes -->
<sphinxql>select j.Str as p from json_case where p is not null order by p asc</sphinxql>
<sphinxql>select j.Str as p from json_case where p is not null order by p desc</sphinxql>
<sphinxql>select j.Str as p from dist_case where p is not null order by p asc</sphinxql>
<sphinxql>select j.Str as p from dist_case where p is not null order by p desc</sphinxql>
<!-- inplace update and strict option -->
<sphinxql>update json_inplace set j.a[0]=5 where id=1</sphinxql>
<sphinxql>select * from json_inplace</sphinxql>
<sphinxql>update json_inplace set j.a[0]=10.0, j.f[1]=3.1415926535 where gid=1</sphinxql>
<sphinxql>select * from json_inplace</sphinxql>
<sphinxql>update json_inplace set j.a[0]=-5 where id=1</sphinxql>
<sphinxql>select * from json_inplace</sphinxql>
<sphinxql>update json_inplace set j.a[1]=-15 where gid>0</sphinxql>
<sphinxql>select * from json_inplace</sphinxql>
<sphinxql>update json_inplace set j.a[1]=-20 where gid=1 option strict=1</sphinxql>
<sphinxql>select * from json_inplace</sphinxql>
<sphinxql>update json_inplace set j.a[1]=-30 where gid>0 option strict=1</sphinxql>
<sphinxql>select * from json_inplace</sphinxql>
<sphinxql>update json_inplace set j.a=5, j.c=5, j.a[0]=5 where gid>0</sphinxql>
<sphinxql>select * from json_inplace</sphinxql>
<sphinxql>update json_inplace set j.a=10, j.c=10, j.a[0]=10 where gid>0 option strict=1</sphinxql>
<sphinxql>select * from json_inplace</sphinxql>
<sphinxql>update json_inplace set j.a=15, j.c=15 where gid=3 option strict=1</sphinxql>
<sphinxql>select * from json_inplace</sphinxql>
<!-- same for rt index -->
<sphinxql>insert into json_inplace_rt (id, gid, title, j) values
( 1,1,'','{"a":[1,2,3,4],"f":[1.0,3.0,2.0]}'),
( 2,1,'','{"a":[2,3,4,5],"f":[2.0,4.0,3.0]}'),
( 3,2,'','{"a":"tag1","b":"tag2"}'),
( 4,3,'','{"a":1,"c":2}')
</sphinxql>
<sphinxql>update json_inplace_rt set j.a[0]=5 where id=1</sphinxql>
<sphinxql>select * from json_inplace_rt</sphinxql>
<sphinxql>update json_inplace_rt set j.a[0]=10.0, j.f[1]=3.1415926535 where gid=1</sphinxql>
<sphinxql>select * from json_inplace_rt</sphinxql>
<sphinxql>update json_inplace_rt set j.a[0]=-5 where id=1</sphinxql>
<sphinxql>select * from json_inplace_rt</sphinxql>
<sphinxql>update json_inplace_rt set j.a[1]=-15 where gid>0</sphinxql>
<sphinxql>select * from json_inplace_rt</sphinxql>
<sphinxql>update json_inplace_rt set j.a[1]=-20 where gid=1 option strict=1</sphinxql>
<sphinxql>select * from json_inplace_rt</sphinxql>
<sphinxql>update json_inplace_rt set j.a[1]=-30 where gid>0 option strict=1</sphinxql>
<sphinxql>select * from json_inplace_rt</sphinxql>
<sphinxql>update json_inplace_rt set j.a=5, j.c=5, j.a[0]=5 where gid>0</sphinxql>
<sphinxql>select * from json_inplace_rt</sphinxql>
<sphinxql>update json_inplace_rt set j.a=10, j.c=10, j.a[0]=10 where gid>0 option strict=1</sphinxql>
<sphinxql>select * from json_inplace_rt</sphinxql>
<sphinxql>update json_inplace_rt set j.a=15, j.c=15 where gid=3 option strict=1</sphinxql>
<sphinxql>select * from json_inplace_rt</sphinxql>
<!-- deadlock regression test -->
<sphinxql>insert into json_inplace_rt (id, gid, title, j) values (666, 666, '', '{}')</sphinxql>
<!-- scientific notation -->
<sphinxql>insert into rt (id, data) values (4, '{"f": 1e-5}')</sphinxql>
<sphinxql>insert into rt (id, data) values (5, '{"f": 1e5}')</sphinxql>
<sphinxql>insert into rt (id, data) values (6, '{"f": -1e-5}')</sphinxql>
<sphinxql>insert into rt (id, data) values (7, '{"f": -1e5}')</sphinxql>
<sphinxql>insert into rt (id, data) values (8, '{"f": 6.022e+3}')</sphinxql>
<sphinxql>insert into rt (id, data) values (9, '{"f": 1.4738223E-1}')</sphinxql>
<sphinxql>select * from rt where id>=4 and id<=9</sphinxql>
<!-- group by json blob -->
<sphinxql>select * from json_inplace_rt group by j</sphinxql>
<sphinxql>select * from json_inplace_rt group by title, j</sphinxql>
<!-- search in arrays -->
<sphinxql>insert into json_search (id, title, j) values
(1, 'a1', '{"array":[{gid:1,name:"a1"},{gid:2,name:"a2"},{gid:3,name:"a3"}], "intarray":[1,2,3], "tags":["a1","a2","a3"]}'),
(2, 'a5', '{"array":[{gid:4,name:"a4"},{gid:5,name:"a5"},{gid:6,name:"a6"}], "intarray":[4,5,6], "tags":["a4","a5","a6"]}'),
(3, 'a9', '{"array":[{gid:7,name:"a7"},{gid:8,name:"a8"},{gid:9,name:"a9"}], "intarray":[7,8,9], "tags":["a7","a8","a9"]}')
</sphinxql>
<sphinxql>select all(x>3 and x<7 for x in j.intarray) from json_search</sphinxql>
<sphinxql>select any(x>1 and x<3 for x in j.intarray) from json_search</sphinxql>
<sphinxql>select indexof(x>2 and x<4 for x in j.intarray) from json_search</sphinxql>
<sphinxql>select all(x>5 for x in j.intarray) from json_search</sphinxql>
<sphinxql>select all(1+x.gid+1>5 for x in j.array) from json_search</sphinxql>
<sphinxql>select indexof(x.gid=any(y.gid=x.gid for y in j.array) for x in j.array) from json_search</sphinxql>
<sphinxql>select id, j.array[indexof(1+x.gid=2 for x in j.array)].name as p from json_search where p is not null</sphinxql>
<sphinxql>select all(z.gid=1 for x in j.array) as error_unknown_column_z from json_search</sphinxql>
<sphinxql>select indexof(x.name='a2' for x in j.array) from json_search</sphinxql>
<sphinxql>select indexof(x.name='a2' or x.name='a6' or x.name='a7' for x in j.array) from json_search</sphinxql>
<sphinxql>select indexof(x.name='a2' or x.gid=6 or x.name='a7' for x in j.array) from json_search</sphinxql>
<sphinxql>select indexof(x.name='a2' and x.gid=2 for x in j.array) from json_search</sphinxql>
<sphinxql>select indexof(x.name=title for x in j.array) from json_search</sphinxql>
<sphinxql>select indexof('a2'=x.name for x in j.array) from json_search</sphinxql>
<sphinxql>select indexof(title=x.name for x in j.array) from json_search</sphinxql>
<sphinxql>select indexof(to_string(1)=to_string(1) for x in j.array) from json_search</sphinxql>
<sphinxql>select all(x='a1' for x in j.tags) from json_search</sphinxql>
<sphinxql>select any(x='a3' for x in j.tags) from json_search</sphinxql>
<sphinxql>select indexof(x='a5' for x in j.tags) from json_search</sphinxql>
<!-- type conversion in the order by clause -->
<sphinxql>insert into json_order (id, j) values
(1, '{i:123,d:123.0,b:12300000000}'),
(2, '{i:23,d:23.0,b:2300000000}'),
(3, '{i:3,d:3.0,b:300000000}')
</sphinxql>
<sphinxql>select j.i from json_order order by j.i asc</sphinxql>
<sphinxql>select j.i from json_order order by integer(j.i) asc</sphinxql>
<sphinxql>select j.d from json_order order by j.d asc</sphinxql>
<sphinxql>select j.d from json_order order by double(j.d) asc</sphinxql>
<sphinxql>select j.b from json_order order by j.b asc</sphinxql>
<sphinxql>select j.b from json_order order by bigint(j.b) asc</sphinxql>
<!-- is null expression -->
<sphinxql>select j[0] is null, if(j[0] is null,0,1), j[0] is not null, if(j[0] is not null,0,1) from objects</sphinxql>
<!-- distributed order by, distributed conversion functions -->
<sphinxql>select id, j.uid from loc1 order by j.uid asc</sphinxql>
<sphinxql>select id, j.uid from loc1 order by j.uid desc</sphinxql>
<sphinxql>select id, j.uid from loc1 order by integer(j.uid) asc</sphinxql>
<sphinxql>select id, j.uid from loc1 order by double(j.uid) asc</sphinxql>
<sphinxql>select id, j.uid from loc1 order by bigint(j.uid) asc</sphinxql>
<!-- distributed order by for aliases -->
<sphinxql>select id, j.uid as p from loc1 order by p asc</sphinxql>
<sphinxql>select id, j.uid as p from loc1 order by p desc</sphinxql>
<!-- group by JSON array elements like for MVA -->
<sphinxql>select count(*), groupby() from arrays group by j.a</sphinxql>
<sphinxql>select count(*), groupby() from arrays group by j.t</sphinxql>
<sphinxql>select count(*) as p, groupby() as q from arrays group by j.t order by q asc, p desc</sphinxql>
<sphinxql>select count(*) as p, groupby() as q from loc1 group by j.uid order by q asc, p desc</sphinxql>
<!-- group by top-level array -->
<sphinxql>insert into json_toplevel (id, j) values
(1, '[1,2,3,4]'),
(2, '[1,2,3]'),
(3, '[1,2]'),
(4, '["a","b","c"]'),
(5, '["a","b"]'),
(6, '["a"]'),
(7, '[]'),
(8, ''),
(9, '{"a":"b"}'),
(10, '{}')
</sphinxql>
<sphinxql>select count(*) p, groupby() q from json_toplevel group by j order by p desc</sphinxql>
<!-- inserting/replacing in a JSONs index with an invalid HTML (quoting) -->
<sphinxql>replace into rt (id, data) values (1,'{"html":"p class="document""}')</sphinxql>
<sphinxql>select data, data.html from rt where id=1</sphinxql>
<sphinxql>replace into rt (id, data) values (1,'{"html":"p class=\"document\""}')</sphinxql>
<sphinxql>select data, data.html from rt where id=1</sphinxql>
<sphinxql>replace into rt (id, data) values (1,'{"html":"p class=\\"document\\""}')</sphinxql>
<sphinxql>select data, data.html from rt where id=1</sphinxql>
<!-- interval function and implicit conversion -->
<sphinxql>select j.a, interval(uint(j.a[0]),1,2,3) from arrays</sphinxql>
<sphinxql>select j.a, interval(j.a[0],1,2,3) from arrays</sphinxql>
<!-- crash on query multiple indexes with order by UPPERCASE json.field -->
<sphinxql>select * from json_up1, json_up2 order by j.R158S asc</sphinxql>
<sphinxql>select * from json_up1, json_up2 order by j.R158S desc</sphinxql>
<sphinxql>select * from json_up1, json_up2 order by j.rom asc</sphinxql>
<sphinxql>select * from json_up1, json_up2 order by j.rom desc</sphinxql>
<sphinxql>select * from dist_up order by j.R158S asc</sphinxql>
<sphinxql>select * from dist_up order by j.R158S desc</sphinxql>
<sphinxql>select * from dist_up order by j.rom asc</sphinxql>
<sphinxql>select * from dist_up order by j.rom desc</sphinxql>
<!-- reserved keyword for distributed indexes -->
<sphinxql>select id, j.id, j.uid from dist</sphinxql>
<!-- is null expression for distributed indexes -->
<sphinxql>select id, j.uid, j.uid is null, j.uid is not null from dist</sphinxql>
<!-- all/any/indexof syntax for distributed indexes -->
<sphinxql>select all(x=1 for x in j.uid), any(x='1' for x in j.uid), indexof(x.uid='1' for x in j.uid) from dist</sphinxql>
<!-- simple string comparison -->
<sphinxql>select title, j.array[0].name, title='a1', j.array[0].name='a4', if(j.array[1].name='a5',0,1) from json_search</sphinxql>
<!-- aliases in functions -->
<sphinxql>select j.array as some_alias, any(some_alias.name>x.name for x in j.array) from json_search</sphinxql>
<sphinxql>select j.intarray as p, p[1], indexof(x>p[1] for x in j.intarray) from json_search</sphinxql>
<!-- crash (OOB) on groupby while remapping fields if there is a NULL attribute -->
<sphinxql>insert into json_remap(id,j1,j2) values (1, '[1]','[1]'), (2, '','[2]')</sphinxql>
<sphinxql>select groupby() from json_remap group by j2</sphinxql>
<!-- group by 1-character string, case-sensitive group by, same for distributed indexes -->
<sphinxql>select count(*), groupby() from json_up1, json_up2 group by j.t1</sphinxql>
<sphinxql>select count(*), groupby() from json_up1, json_up2 group by j.T1</sphinxql>
<sphinxql>select count(*), groupby() from dist_up group by j.t1</sphinxql>
<sphinxql>select count(*), groupby() from dist_up group by j.T1</sphinxql>
<!-- json field type autoconversion in expressions, types should match -->
<sphinxql>select integer(j.rom)=202 as p from json_up1</sphinxql>
<sphinxql>select j.rom=202 as p from json_up1</sphinxql>
<sphinxql>select j.rom='202' as p from json_up1</sphinxql>
<!-- is null vs non-json fields, json-dependent columns vs order by -->
<sphinxql>select id as v, double(v) as dv, v is null, v is not null from dist_up</sphinxql>
<sphinxql>select j.rom as v, double(v) as dv, v is null, v is not null from dist_up</sphinxql>
<sphinxql>select j.rom as v, double(v) as dv, v is null, v is not null from dist_up order by dv asc</sphinxql>
<!-- inplace update for several 64-bit values -->
<sphinxql>update json_inplace set j.f[0]=345345345354, j.f[1]=777 where id=1</sphinxql>
<sphinxql>select j.f[0], j.f[1] from json_inplace where id=1</sphinxql>
<sphinxql>update json_inplace_rt set j.f[0]=345345345354, j.f[1]=777 where id=1</sphinxql>
<sphinxql>select j.f[0], j.f[1] from json_inplace_rt where id=1</sphinxql>
<!-- type autoconversion for 64-bit values -->
<sphinxql>select j.f, indexof(x>345345345353 for x in j.f) as p from json_inplace where p=0</sphinxql>
<!-- group by aliased field -->
<sphinxql>select id, count(*), groupby(), j.a as p from arrays where id=123 group by p</sphinxql>
<!-- true/false/null filtered as integers -->
<sphinxql>select j from objects where id=9 and j[0]=0 and j[1]=1 and j[2]=0</sphinxql>
<sphinxql>select j from objects where id=9 and j[0]!=1 and j[1]>1 and j[2]<1</sphinxql>
</sphqueries>
</test>
|