فهرست منبع

Add shell for ESQL docs (ESQL-913)

This adds a super basic shell for the esql docs. You can build them with
the standard docs build commend:
```
../docs/build_docs --doc docs/reference/index.asciidoc \
  --resource x-pack/docs/ --chunk 1 --open
```
Nik Everett 2 سال پیش
والد
کامیت
02e8293f54

+ 17 - 0
docs/reference/esql/from.asciidoc

@@ -0,0 +1,17 @@
+[[esql-from]]
+== `from`
+
+The `from` keyword in ESQL chooses which index to query.
+
+[source,esql]
+----
+include::{esql-specs}/docs.csv-spec[tag=from]
+----
+
+You can match indices with a glob pattern:
+
+<insert example>
+
+And you can use commas to separate multiple patterns:
+
+<insert example>

+ 54 - 0
docs/reference/esql/index.asciidoc

@@ -0,0 +1,54 @@
+[[esql]]
+= ESQL
+
+:esql-tests: {xes-repo-dir}/../../plugin/esql/qa
+:esql-specs: {esql-tests}/testFixtures/src/main/resources
+
+[partintro]
+--
+ESQL is a glorious new language to query data in Elasticsearch!
+
+[discrete]
+[[esql-console]]
+=== Run ESQL!
+
+[source,console]
+----
+POST /_esql
+{
+  "query": """
+    FROM library
+    | EVAL year = DATE_TRUNC(release_date, 1 YEARS)
+    | STATS MAX(page_count) BY year
+    | SORT year
+    | LIMIT 5
+  """
+}
+----
+// TEST[setup:library]
+
+The results come back in rows:
+
+[source,console-result]
+----
+{
+  "columns": [
+    { "name": "MAX(page_count)", "type": "integer"},
+    { "name": "year"           , "type": "date"}
+  ],
+  "values": [
+    [268, "1932-01-01T00:00:00.000Z"],
+    [224, "1951-01-01T00:00:00.000Z"],
+    [227, "1953-01-01T00:00:00.000Z"],
+    [335, "1959-01-01T00:00:00.000Z"],
+    [604, "1965-01-01T00:00:00.000Z"]
+  ]
+}
+----
+
+--
+
+include::from.asciidoc[]
+
+:esql-tests!:
+:esql-specs!:

+ 5 - 0
docs/reference/index.asciidoc

@@ -1,6 +1,9 @@
 [[elasticsearch-reference]]
 = Elasticsearch Guide
 
+// Temporary workaround until we merge into the primary Elasticsearch branch.
+:elasticsearch-root: {elasticsearch-internal-root}
+
 :include-xpack:         true
 :es-test-dir:           {elasticsearch-root}/docs/src/test
 :plugins-examples-dir:  {elasticsearch-root}/plugins/examples
@@ -43,6 +46,8 @@ include::geospatial-analysis.asciidoc[]
 
 include::eql/eql.asciidoc[]
 
+include::esql/index.asciidoc[]
+
 include::sql/index.asciidoc[]
 
 include::scripting.asciidoc[]

+ 15 - 0
x-pack/plugin/esql/qa/testFixtures/src/main/resources/docs.csv-spec

@@ -0,0 +1,15 @@
+// This spec contains examples that are included in the docs that don't fit into any other file.
+// The docs can and do include examples from other files.
+
+from
+// tag::from[]
+FROM test
+// end::from[]
+| PROJECT emp_no
+| SORT emp_no
+| LIMIT 1
+;
+
+emp_no:integer
+10001
+;

+ 2 - 1
x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/ExpressionBuilder.java

@@ -44,6 +44,7 @@ import java.time.Duration;
 import java.time.Period;
 import java.time.ZoneId;
 import java.util.List;
+import java.util.Locale;
 
 import static org.elasticsearch.xpack.esql.type.EsqlDataTypes.DATE_PERIOD;
 import static org.elasticsearch.xpack.esql.type.EsqlDataTypes.TIME_DURATION;
@@ -124,7 +125,7 @@ public class ExpressionBuilder extends IdentifierBuilder {
         Source source = source(ctx);
         Literal intLit = typedParsing(this, ctx.integerValue(), Literal.class);
         Integer value = (Integer) intLit.value();
-        String qualifier = ctx.UNQUOTED_IDENTIFIER().getText();
+        String qualifier = ctx.UNQUOTED_IDENTIFIER().getText().toLowerCase(Locale.ROOT);
 
         return switch (qualifier) {
             case "millisecond", "milliseconds" -> new Literal(source, Duration.ofMillis(value), TIME_DURATION);

+ 4 - 0
x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/ExpressionTests.java

@@ -330,6 +330,10 @@ public class ExpressionTests extends ESTestCase {
             whereExpression("10 days > 5 hours and 1/5 minutes > 8 seconds * 3 and -1 minutes > foo"),
             equalTo(whereExpression("((10 days) > (5 hours)) and ((1/(5 minutes) > ((8 seconds) * 3))) and (-(1 minute) > foo)"))
         );
+        assertThat(
+            whereExpression("10 DAYS > 5 HOURS and 1/5 MINUTES > 8 SECONDS * 3 and -1 MINUTES > foo"),
+            equalTo(whereExpression("((10 days) > (5 hours)) and ((1/(5 minutes) > ((8 seconds) * 3))) and (-(1 minute) > foo)"))
+        );
     }
 
     public void testFunctionExpressions() {