diff options
author | Jon Bratseth <bratseth@gmail.com> | 2022-11-02 11:07:19 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2022-11-02 11:07:19 +0100 |
commit | 933f874a3a8d10bad01f07942a65d25165d4fcfa (patch) | |
tree | 7b9623703f323081a0e945b7fb93722e5cf76fe8 /client/src | |
parent | 349e575f85448b66789cdf42444b7779460970a0 (diff) |
Deprecate semicolon()
Diffstat (limited to 'client/src')
-rw-r--r-- | client/src/main/java/ai/vespa/client/dsl/EndQuery.java | 14 | ||||
-rw-r--r-- | client/src/main/java/ai/vespa/client/dsl/Query.java | 22 | ||||
-rw-r--r-- | client/src/test/java/ai/vespa/client/dsl/QTest.java | 62 |
3 files changed, 33 insertions, 65 deletions
diff --git a/client/src/main/java/ai/vespa/client/dsl/EndQuery.java b/client/src/main/java/ai/vespa/client/dsl/EndQuery.java index 61ffe84e5a9..1550186342e 100644 --- a/client/src/main/java/ai/vespa/client/dsl/EndQuery.java +++ b/client/src/main/java/ai/vespa/client/dsl/EndQuery.java @@ -76,15 +76,21 @@ public class EndQuery { } /** - * Semicolon. - * turn a query into fixed query. + * Calls fix() * - * @return the fixed query + * @deprecated use {link #fix} */ - public FixedQuery semicolon() { + @Deprecated // TODO: Remove on Vespa 9 + public FixedQuery semicolon() { return fix(); } + + /** Returns a fixed query containing this. */ + public FixedQuery fix() { return new FixedQuery(this); } + /** Calls fix().build() */ + public String build() { return fix().build(); } + /** * Group. * https://docs.vespa.ai/en/reference/query-language-reference.html#grouping diff --git a/client/src/main/java/ai/vespa/client/dsl/Query.java b/client/src/main/java/ai/vespa/client/dsl/Query.java index bc5be2280c4..36718ced814 100644 --- a/client/src/main/java/ai/vespa/client/dsl/Query.java +++ b/client/src/main/java/ai/vespa/client/dsl/Query.java @@ -290,13 +290,27 @@ public class Query extends QueryChain { } /** - * Semicolon. - * turn a query into fixed query. + * Calls fix() * * @return the fixed query + * @deprecated use {@link #fix()}, {@link #end()} or {@link #build} instead */ - public FixedQuery semicolon() { - return new FixedQuery(new EndQuery(this)); + @Deprecated // TODO: Remove on Vespa 9 + public FixedQuery semicolon() { return fix(); } + + /** Returns this as an ended query. */ + public EndQuery end() { + return new EndQuery(this); + } + + /** Calls end().fix(). */ + public FixedQuery fix() { + return end().fix(); + } + + /** Calls fix().build(). */ + public String build() { + return fix().build(); } @Override diff --git a/client/src/test/java/ai/vespa/client/dsl/QTest.java b/client/src/test/java/ai/vespa/client/dsl/QTest.java index 114cbee0177..ed9198b3bde 100644 --- a/client/src/test/java/ai/vespa/client/dsl/QTest.java +++ b/client/src/test/java/ai/vespa/client/dsl/QTest.java @@ -25,7 +25,6 @@ class QTest { String q = Q.select("f1", "f2") .from("sd1") .where("f1").contains("v1") - .semicolon() .build(); assertEquals(q, "yql=select f1, f2 from sd1 where f1 contains \"v1\";"); @@ -36,7 +35,6 @@ class QTest { String q = Q.select("*") .from("sd1") .where("f1").contains("v1") - .semicolon() .build(); assertEquals(q, "yql=select * from sd1 where f1 contains \"v1\";"); @@ -47,7 +45,6 @@ class QTest { String q = Q.select("*") .from("sd1", "sd2") .where("f1").contains("v1") - .semicolon() .build(); assertEquals(q, "yql=select * from sources sd1, sd2 where f1 contains \"v1\";"); @@ -66,7 +63,7 @@ class QTest { .timeout(3) .orderByDesc("f1") .orderByAsc("f2") - .semicolon() + .fix() .param("paramk1", "paramv1") .build(); @@ -81,7 +78,6 @@ class QTest { .and("f2").matches("v2") .or("f3").matches("v3") .andnot("f4").matches("v4") - .semicolon() .build(); assertEquals(q, "yql=select * from sd1 where f1 matches \"v1\" and f2 matches \"v2\" or f3 matches \"v3\" and !(f4 matches \"v4\");"); @@ -97,7 +93,6 @@ class QTest { .and("f4").gt(4) .and("f5").eq(5) .and("f6").inRange(6, 7) - .semicolon() .build(); assertEquals(q, "yql=select * from sd1 where f1 <= 1 and f2 < 2 and f3 >= 3 and f4 > 4 and f5 = 5 and range(f6, 6, 7);"); @@ -113,7 +108,6 @@ class QTest { .and("f4").gt(4L) .and("f5").eq(5L) .and("f6").inRange(6L, 7L) - .semicolon() .build(); assertEquals(q, "yql=select * from sd1 where f1 <= 1L and f2 < 2L and f3 >= 3L and f4 > 4L and f5 = 5L and range(f6, 6L, 7L);"); @@ -129,7 +123,6 @@ class QTest { .and("f4").gt(4.4) .and("f5").eq(5.5) .and("f6").inRange(6.6, 7.7) - .semicolon() .build(); assertEquals(q, "yql=select * from sd1 where f1 <= 1.1 and f2 < 2.2 and f3 >= 3.3 and f4 > 4.4 and f5 = 5.5 and range(f6, 6.6, 7.7);"); @@ -145,7 +138,6 @@ class QTest { .and("f4").gt(4.4D) .and("f5").eq(5.5D) .and("f6").inRange(6.6D, 7.7D) - .semicolon() .build(); assertEquals(q, "yql=select * from sd1 where f1 <= 1.1 and f2 < 2.2 and f3 >= 3.3 and f4 > 4.4 and f5 = 5.5 and range(f6, 6.6, 7.7);"); @@ -158,7 +150,6 @@ class QTest { .where("f1").contains("1") .andnot(Q.p(Q.p("f2").contains("2").and("f3").contains("3")) .or(Q.p("f2").contains("4").andnot("f3").contains("5"))) - .semicolon() .build(); assertEquals(q, "yql=select * from sd1 where f1 contains \"1\" and !((f2 contains \"2\" and f3 contains \"3\") or (f2 contains \"4\" and !(f3 contains \"5\")));"); @@ -170,7 +161,6 @@ class QTest { .from("sd1") .where(Q.ui("value1")) .and(Q.ui("index", "value2")) - .semicolon() .build(); assertEquals("yql=select * from sd1 where userInput(\"value1\") and ({\"defaultIndex\":\"index\"}userInput(\"value2\"));", q); } @@ -181,7 +171,7 @@ class QTest { .from("site") .where(Q.rank(Q.p("docQ").nearestNeighbor("vectorQuery"), Q.ui("@query"))) - .semicolon().build(); + .build(); assertEquals("yql=select url from site where rank(nearestNeighbor(docQ, vectorQuery), userInput(@query));", q); } @@ -191,7 +181,6 @@ class QTest { .from("sd1") .where(Q.dotPdt("f1", stringIntMap("a", 1, "b", 2, "c", 3))) .and("f2").contains("1") - .semicolon() .build(); assertEquals("yql=select * from sd1 where dotProduct(f1, {\"a\":1,\"b\":2,\"c\":3}) and f2 contains \"1\";", q); @@ -203,7 +192,6 @@ class QTest { .from("sd1") .where(Q.wtdSet("f1", stringIntMap("a", 1, "b", 2, "c", 3))) .and("f2").contains("1") - .semicolon() .build(); assertEquals(q, "yql=select * from sd1 where weightedSet(f1, {\"a\":1,\"b\":2,\"c\":3}) and f2 contains \"1\";"); @@ -215,7 +203,6 @@ class QTest { .from("sd1") .where(Q.nonEmpty(Q.p("f1").contains("v1"))) .and("f2").contains("v2") - .semicolon() .build(); assertEquals(q, "yql=select * from sd1 where nonEmpty(f1 contains \"v1\") and f2 contains \"v2\";"); @@ -232,7 +219,6 @@ class QTest { Q.wand("f3", Arrays.asList(Arrays.asList(1, 1), Arrays.asList(2, 2))) .annotate(A.a("scoreThreshold", 0.13)) ) - .semicolon() .build(); assertEquals(q, "yql=select * from sd1 where wand(f1, {\"a\":1,\"b\":2,\"c\":3}) and wand(f2, [[1,1],[2,2]]) and ([{\"scoreThreshold\":0.13}]wand(f3, [[1,1],[2,2]]));"); @@ -246,7 +232,6 @@ class QTest { .and(Q.weakand(Q.p("f1").contains("v1").and("f2").contains("v2")) .annotate(A.a("scoreThreshold", 0.13)) ) - .semicolon() .build(); assertEquals(q, "yql=select * from sd1 where weakAnd(f1 contains \"v1\", f2 contains \"v2\") and ([{\"scoreThreshold\":0.13}]weakAnd(f1 contains \"v1\", f2 contains \"v2\"));"); @@ -257,7 +242,6 @@ class QTest { String q = Q.select("*") .from("sd1") .where("a").contains("b").and(Q.geoLocation("taiwan", 25.105497, 121.597366, "200km")) - .semicolon() .build(); assertEquals(q, "yql=select * from sd1 where a contains \"b\" and geoLocation(taiwan, 25.105497, 121.597366, \"200km\");"); @@ -271,7 +255,6 @@ class QTest { .and(Q.nearestNeighbor("vec1", "vec2") .annotate(A.a("targetHits", 10, "approximate", false)) ) - .semicolon() .build(); assertEquals(q, "yql=select * from sd1 where a contains \"b\" and ([{\"approximate\":false,\"targetHits\":10}]nearestNeighbor(vec1, vec2));"); } @@ -282,7 +265,6 @@ class QTest { () -> Q.select("*") .from("sd1") .where("a").contains("b").and(Q.nearestNeighbor("vec1", "vec2")) - .semicolon() .build()); } @@ -295,7 +277,6 @@ class QTest { Q.p("f1").contains("v1") ) ) - .semicolon() .build(); assertEquals(q, "yql=select * from sd1 where rank(f1 contains \"v1\");"); @@ -310,7 +291,6 @@ class QTest { Q.p("f2").contains("v2"), Q.p("f3").eq(3)) ) - .semicolon() .build(); assertEquals(q, "yql=select * from sd1 where rank(f1 contains \"v1\", f2 contains \"v2\", f3 = 3);"); @@ -325,7 +305,6 @@ class QTest { Q.p("f1").contains("v1"), ranks) ) - .semicolon() .build(); assertEquals(q, "yql=select * from sd1 where rank(f1 contains \"v1\", f2 contains \"v2\", f3 = 3);"); @@ -333,14 +312,12 @@ class QTest { @Test void stringfunction_annotations() { - { Annotation annotation = A.filter(); String expected = "[{\"filter\":true}]"; String q = Q.select("*") .from("sd1") .where("f1").contains(annotation, "v1") - .semicolon() .build(); assertEquals(q, "yql=select * from sd1 where f1 contains (" + expected + "\"v1\");"); @@ -351,7 +328,6 @@ class QTest { String q = Q.select("*") .from("sd1") .where("f1").contains(annotation, "v1") - .semicolon() .build(); assertEquals(q, "yql=select * from sd1 where f1 contains (" + expected + "\"v1\");"); @@ -362,7 +338,6 @@ class QTest { String q = Q.select("*") .from("sd1") .where("f1").contains(annotation, "v1") - .semicolon() .build(); assertEquals(q, "yql=select * from sd1 where f1 contains (" + expected + "\"v1\");"); @@ -375,7 +350,6 @@ class QTest { String q = Q.select("*") .from("sd1") .where("f1").contains("v1").annotate(A.a("ak1", "av1")) - .semicolon() .build(); assertEquals(q, "yql=select * from sd1 where ([{\"ak1\":\"av1\"}](f1 contains \"v1\"));"); @@ -386,7 +360,6 @@ class QTest { String q = Q.select("*") .from("sd1") .where(Q.p("f1").contains("v1").annotate(A.a("ak1", "av1")).and("f2").contains("v2")) - .semicolon() .build(); assertEquals(q, "yql=select * from sd1 where ([{\"ak1\":\"av1\"}](f1 contains \"v1\" and f2 contains \"v2\"));"); @@ -400,7 +373,6 @@ class QTest { Q.p("f1").contains("v1").annotate(A.a("ak1", "av1"))) .and("f2").contains("v2") ) - .semicolon() .build(); assertEquals(q, "yql=select * from sd1 where (([{\"ak1\":\"av1\"}](f1 contains \"v1\")) and f2 contains \"v2\");"); @@ -409,7 +381,6 @@ class QTest { @Test void build_query_which_created_from_Q_b_without_select_and_sources() { String q = Q.p("f1").contains("v1") - .semicolon() .build(); assertEquals(q, "yql=select * from sources * where f1 contains \"v1\";"); @@ -422,7 +393,6 @@ class QTest { .orderByAsc(A.a(stringObjMap("function", "uca", "locale", "en_US", "strength", "IDENTICAL")), "f3") .orderByDesc("f4") .orderByDesc(A.a(stringObjMap("function", "lowercase")), "f5") - .semicolon() .build(); assertEquals(q, "yql=select * from sources * where f1 contains \"v1\" order by f2 asc, [{\"function\":\"uca\",\"locale\":\"en_US\",\"strength\":\"IDENTICAL\"}]f3 asc, f4 desc, [{\"function\":\"lowercase\"}]f5 desc;"); @@ -431,7 +401,6 @@ class QTest { @Test void contains_sameElement() { String q = Q.p("f1").containsSameElement(Q.p("stime").le(1).and("etime").gt(2)) - .semicolon() .build(); assertEquals(q, "yql=select * from sources * where f1 contains sameElement(stime <= 1, etime > 2);"); @@ -441,40 +410,32 @@ class QTest { void contains_phrase_near_onear_equiv() { { String q1 = Q.p("f1").containsPhrase("p1", "p2", "p3") - .semicolon() .build(); String q2 = Q.p("f1").containsPhrase(Arrays.asList("p1", "p2", "p3")) - .semicolon() .build(); assertEquals(q1, "yql=select * from sources * where f1 contains phrase(\"p1\", \"p2\", \"p3\");"); assertEquals(q2, "yql=select * from sources * where f1 contains phrase(\"p1\", \"p2\", \"p3\");"); } { String q1 = Q.p("f1").containsNear("p1", "p2", "p3") - .semicolon() .build(); String q2 = Q.p("f1").containsNear(Arrays.asList("p1", "p2", "p3")) - .semicolon() .build(); assertEquals(q1, "yql=select * from sources * where f1 contains near(\"p1\", \"p2\", \"p3\");"); assertEquals(q2, "yql=select * from sources * where f1 contains near(\"p1\", \"p2\", \"p3\");"); } { String q1 = Q.p("f1").containsOnear("p1", "p2", "p3") - .semicolon() .build(); String q2 = Q.p("f1").containsOnear(Arrays.asList("p1", "p2", "p3")) - .semicolon() .build(); assertEquals(q1, "yql=select * from sources * where f1 contains onear(\"p1\", \"p2\", \"p3\");"); assertEquals(q2, "yql=select * from sources * where f1 contains onear(\"p1\", \"p2\", \"p3\");"); } { String q1 = Q.p("f1").containsEquiv("p1", "p2", "p3") - .semicolon() .build(); String q2 = Q.p("f1").containsEquiv(Arrays.asList("p1", "p2", "p3")) - .semicolon() .build(); assertEquals(q1, "yql=select * from sources * where f1 contains equiv(\"p1\", \"p2\", \"p3\");"); assertEquals(q2, "yql=select * from sources * where f1 contains equiv(\"p1\", \"p2\", \"p3\");"); @@ -484,7 +445,6 @@ class QTest { @Test void contains_uri() { String q = Q.p("f1").containsUri("https://test.uri") - .semicolon() .build(); assertEquals(q, "yql=select * from sources * where f1 contains uri(\"https://test.uri\");"); @@ -493,7 +453,6 @@ class QTest { @Test void contains_uri_with_annotation() { String q = Q.p("f1").containsUri(A.a("key", "value"), "https://test.uri") - .semicolon() .build(); assertEquals(q, "yql=select * from sources * where f1 contains ([{\"key\":\"value\"}]uri(\"https://test.uri\"));"); @@ -502,7 +461,6 @@ class QTest { @Test void nearestNeighbor() { String q = Q.p("f1").nearestNeighbor("query_vector") - .semicolon() .build(); assertEquals(q, "yql=select * from sources * where nearestNeighbor(f1, query_vector);"); @@ -511,7 +469,6 @@ class QTest { @Test void nearestNeighbor_with_annotation() { String q = Q.p("f1").nearestNeighbor(A.a("targetHits", 10), "query_vector") - .semicolon() .build(); assertEquals(q, "yql=select * from sources * where ([{\"targetHits\":10}]nearestNeighbor(f1, query_vector));"); @@ -520,7 +477,6 @@ class QTest { @Test void use_contains_instead_of_contains_equiv_when_input_size_is_1() { String q = Q.p("f1").containsEquiv(Collections.singletonList("p1")) - .semicolon() .build(); assertEquals(q, "yql=select * from sources * where f1 contains \"p1\";"); @@ -529,19 +485,15 @@ class QTest { @Test void contains_phrase_near_onear_equiv_empty_list_should_throw_illegal_argument_exception() { assertThrows(IllegalArgumentException.class, () -> Q.p("f1").containsPhrase(Collections.emptyList()) - .semicolon() .build()); assertThrows(IllegalArgumentException.class, () -> Q.p("f1").containsNear(Collections.emptyList()) - .semicolon() .build()); assertThrows(IllegalArgumentException.class, () -> Q.p("f1").containsOnear(Collections.emptyList()) - .semicolon() .build()); assertThrows(IllegalArgumentException.class, () -> Q.p("f1").containsEquiv(Collections.emptyList()) - .semicolon() .build()); } @@ -550,14 +502,12 @@ class QTest { void contains_near_onear_with_annotation() { { String q = Q.p("f1").containsNear(A.a("distance", 5), "p1", "p2", "p3") - .semicolon() .build(); assertEquals(q, "yql=select * from sources * where f1 contains ([{\"distance\":5}]near(\"p1\", \"p2\", \"p3\"));"); } { String q = Q.p("f1").containsOnear(A.a("distance", 5), "p1", "p2", "p3") - .semicolon() .build(); assertEquals(q, "yql=select * from sources * where f1 contains ([{\"distance\":5}]onear(\"p1\", \"p2\", \"p3\"));"); @@ -588,7 +538,6 @@ class QTest { )) )) ) - .semicolon() .build(); assertEquals(q, "yql=select * from sources * where f1 contains \"v1\" | all(group(a) max(5) each(output(count()) all(max(1) each(output(summary()))) all(group(b) each(output(count()) all(max(1) each(output(summary()))) all(group(c) each(output(count()) all(max(1) each(output(summary())))))))));"); @@ -608,7 +557,6 @@ class QTest { */ String q = Q.p("f1").contains("v1") .group("all(group(a) max(5) each(output(count()) all(max(1) each(output(summary()))) all(group(b) each(output(count()) all(max(1) each(output(summary()))) all(group(c) each(output(count()) all(max(1) each(output(summary())))))))))") - .semicolon() .build(); assertEquals(q, "yql=select * from sources * where f1 contains \"v1\" | all(group(a) max(5) each(output(count()) all(max(1) each(output(summary()))) all(group(b) each(output(count()) all(max(1) each(output(summary()))) all(group(c) each(output(count()) all(max(1) each(output(summary())))))))));"); @@ -631,7 +579,7 @@ class QTest { .reduce(Query::and) .get(); - assertEquals(q.semicolon().build(), "yql=select * from sources * where a contains \"1\" and b contains \"2\" and c contains \"3\";"); + assertEquals(q.build(), "yql=select * from sources * where a contains \"1\" and b contains \"2\" and c contains \"3\";"); } @Test @@ -641,12 +589,12 @@ class QTest { map.forEach((k, v) -> q.and(Q.p(k).contains(v))); - assertEquals(q.semicolon().build(), "yql=select * from sources * where a contains \"1\" and b contains \"2\" and c contains \"3\";"); + assertEquals(q.build(), "yql=select * from sources * where a contains \"1\" and b contains \"2\" and c contains \"3\";"); } @Test void empty_queries_should_not_print_out() { - String q = Q.p(Q.p(Q.p().andnot(Q.p()).and(Q.p()))).and("a").contains("1").semicolon().build(); + String q = Q.p(Q.p(Q.p().andnot(Q.p()).and(Q.p()))).and("a").contains("1").build(); assertEquals(q, "yql=select * from sources * where a contains \"1\";"); } |