You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by th...@apache.org on 2021/07/29 16:13:49 UTC

[solr] branch main updated: SOLR-15566: Clarify ref guide documentation about SQL queries with SELECT * requiring a LIMIT clause (#237)

This is an automated email from the ASF dual-hosted git repository.

thelabdude pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/main by this push:
     new 632852a  SOLR-15566: Clarify ref guide documentation about SQL queries with SELECT * requiring a LIMIT clause (#237)
632852a is described below

commit 632852aea3269342d5b70aacc69ba1101855204b
Author: Timothy Potter <th...@gmail.com>
AuthorDate: Thu Jul 29 10:13:46 2021 -0600

    SOLR-15566: Clarify ref guide documentation about SQL queries with SELECT * requiring a LIMIT clause (#237)
---
 solr/CHANGES.txt                                           |  2 +-
 .../src/test/org/apache/solr/handler/TestSQLHandler.java   | 14 ++++++++++++++
 solr/solr-ref-guide/src/parallel-sql-interface.adoc        |  8 ++++++--
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index a48b57f..3b9da07 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -398,7 +398,7 @@ Bug Fixes
 
 Other Changes
 ---------------------
-(No changes)
+* SOLR-15566: Clarify ref guide documentation about SQL queries with `SELECT *` requiring a `LIMIT` clause (Timothy Potter)
 
 ==================  8.9.0 ==================
 
diff --git a/solr/core/src/test/org/apache/solr/handler/TestSQLHandler.java b/solr/core/src/test/org/apache/solr/handler/TestSQLHandler.java
index 2a410d7..c3420fd 100644
--- a/solr/core/src/test/org/apache/solr/handler/TestSQLHandler.java
+++ b/solr/core/src/test/org/apache/solr/handler/TestSQLHandler.java
@@ -2218,4 +2218,18 @@ public class TestSQLHandler extends SolrCloudTestCase {
     String country = id % 2 == 0 ? "US" : "CA";
     return updateRequest.add("id", String.valueOf(id), "str_s", String.format(Locale.ROOT, padFmt, id % cardinality), "country_s", country);
   }
+
+  @Test
+  public void testSelectStarWithLimit() throws Exception {
+    new UpdateRequest()
+        .add("id", "1", "a_s", "hello-1", "b_s", "foo", "c_s", "bar", "d_s", "x")
+        .add("id", "2", "a_s", "world-2", "b_s", "foo", "a_i", "2", "d_s", "a")
+        .add("id", "3", "a_s", "hello-3", "b_s", "foo", "c_s", "bar", "d_s", "x")
+        .add("id", "4", "a_s", "world-4", "b_s", "foo", "a_i", "3", "d_s", "b")
+        .commit(cluster.getSolrClient(), COLLECTIONORALIAS);
+
+    expectResults("SELECT * FROM $ALIAS LIMIT 100", 4);
+    // select * w/o limit is not supported by Solr SQL
+    expectThrows(IOException.class, () -> expectResults("SELECT * FROM $ALIAS", -1));
+  }
 }
diff --git a/solr/solr-ref-guide/src/parallel-sql-interface.adoc b/solr/solr-ref-guide/src/parallel-sql-interface.adoc
index b8c47c2..7837b95 100644
--- a/solr/solr-ref-guide/src/parallel-sql-interface.adoc
+++ b/solr/solr-ref-guide/src/parallel-sql-interface.adoc
@@ -201,10 +201,14 @@ The SQL parser being used by Solr to translate the SQL statements is case insens
 However, for ease of reading, all examples on this page use capitalized keywords.
 ====
 
-.SELECT * is not supported
+.SELECT * is only supported when using LIMIT
 [IMPORTANT]
 ====
-The SQL parser being used by Solr does not support the SELECT * syntax, you must specify each field you wish to return.
+In general, you should project the fields you need to return for each query explicitly and avoid using `select *`, which is generally considered a bad practice and
+can lead to unexpected results when the underlying Solr schema changes.
+However, Solr does support `select *` for queries that also include a `LIMIT` clause.
+All stored fields and the `score` will be included in the results.
+Without a `LIMIT` clause, only fields with docValues enabled can be returned.
 ====
 
 === Escaping Reserved Words