Skip to content

Commit 42d705a

Browse files
committed
Merge branch 'default-main'
* default-main: (34 commits) Enhance dynamic source clause to support only metadata filters (#4554) Make nested alias type support referring to outer context (#4673) Update big5 ppl queries and check plans (#4668) Support push down sort after limit (#4657) Use table scan rowType in filter pushdown could fix rename issue (#4670) Fix: Support Alias Fields in MIN, MAX, FIRST, LAST, and TAKE Aggregations (#4621) Fix bin nested fields issue (#4606) Add `per_minute`, `per_hour`, `per_day` function support (#4531) Pushdown sort aggregate metrics (#4603) Followup: Change ComparableLinkedHashMap to compare Key than Value (#4648) Mitigate the CI failure caused by 500 Internal Server Error (#4646) Allow renaming group-by fields to existing field names (#4586) Publish internal modules separately for downstream reuse (#4484) Revert "Update grammar files and developer guide (#4301)" (#4643) Support Automatic Type Conversion for REX/SPATH/PARSE Command Extractions (#4599) Replace all dots in fields of table scan's PhysType (#4633) Return comparable LinkedHashMap in `valueForCalcite()` of ExprTupleValue (#4629) Refactor JsonExtractAllFunctionIT and MapConcatFunctionIT (#4623) Pushdown case function in aggregations as range queries (#4400) Update GEOIP function to support IP types as input (#4613) ... Signed-off-by: Asif Bashar <[email protected]>
2 parents 1420e8f + e6eb808 commit 42d705a

File tree

447 files changed

+13893
-2613
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

447 files changed

+13893
-2613
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Publish unified query modules to maven
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
- '[0-9]+.[0-9]+'
9+
- '[0-9]+.x'
10+
11+
env:
12+
SNAPSHOT_REPO_URL: https://ci.opensearch.org/ci/dbc/snapshots/maven/
13+
14+
jobs:
15+
publish-unified-query-modules:
16+
strategy:
17+
fail-fast: false
18+
if: github.repository == 'opensearch-project/sql'
19+
runs-on: ubuntu-latest
20+
21+
permissions:
22+
id-token: write
23+
contents: write
24+
25+
steps:
26+
- uses: actions/setup-java@v3
27+
with:
28+
distribution: temurin # Temurin is a distribution of adoptium
29+
java-version: 21
30+
- uses: actions/checkout@v3
31+
- name: Load secret
32+
uses: 1password/load-secrets-action@v2
33+
with:
34+
# Export loaded secrets as environment variables
35+
export-env: true
36+
env:
37+
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
38+
MAVEN_SNAPSHOTS_S3_REPO: op://opensearch-infra-secrets/maven-snapshots-s3/repo
39+
MAVEN_SNAPSHOTS_S3_ROLE: op://opensearch-infra-secrets/maven-snapshots-s3/role
40+
- name: Configure AWS credentials
41+
uses: aws-actions/configure-aws-credentials@v5
42+
with:
43+
role-to-assume: ${{ env.MAVEN_SNAPSHOTS_S3_ROLE }}
44+
aws-region: us-east-1
45+
- name: publish snapshots to maven
46+
run: |
47+
./gradlew publishUnifiedQueryPublicationToSnapshotsRepository

.github/workflows/maven-publish.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ on:
55
push:
66
branches:
77
- main
8-
- 1.*
9-
- 2.*
10-
11-
env:
12-
SNAPSHOT_REPO_URL: https://central.sonatype.com/repository/maven-snapshots/
8+
- '[0-9]+.[0-9]+'
9+
- '[0-9]+.x'
1310

1411
jobs:
1512
build-and-publish-snapshots:
@@ -35,9 +32,13 @@ jobs:
3532
export-env: true
3633
env:
3734
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
38-
SONATYPE_USERNAME: op://opensearch-infra-secrets/maven-central-portal-credentials/username
39-
SONATYPE_PASSWORD: op://opensearch-infra-secrets/maven-central-portal-credentials/password
40-
35+
MAVEN_SNAPSHOTS_S3_REPO: op://opensearch-infra-secrets/maven-snapshots-s3/repo
36+
MAVEN_SNAPSHOTS_S3_ROLE: op://opensearch-infra-secrets/maven-snapshots-s3/role
37+
- name: Configure AWS credentials
38+
uses: aws-actions/configure-aws-credentials@v5
39+
with:
40+
role-to-assume: ${{ env.MAVEN_SNAPSHOTS_S3_ROLE }}
41+
aws-region: us-east-1
4142
- name: publish snapshots to maven
4243
run: |
43-
./gradlew publishPluginZipPublicationToSnapshotsRepository
44+
./gradlew publishPluginZipPublicationToSnapshotsRepository

.github/workflows/publish-async-query-core.yml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ on:
55
push:
66
branches:
77
- main
8-
- 1.*
9-
- 2.*
8+
- '[0-9]+.[0-9]+'
9+
- '[0-9]+.x'
1010
paths:
1111
- 'async-query-core/**'
1212
- '.github/workflows/publish-async-query-core.yml'
@@ -18,7 +18,6 @@ concurrency:
1818
cancel-in-progress: false
1919

2020
env:
21-
SNAPSHOT_REPO_URL: https://central.sonatype.com/repository/maven-snapshots/
2221
COMMIT_MAP_FILENAME: commit-history-async-query-core.json
2322

2423
jobs:
@@ -47,8 +46,19 @@ jobs:
4746
export-env: true
4847
env:
4948
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
50-
SONATYPE_USERNAME: op://opensearch-infra-secrets/maven-central-portal-credentials/username
51-
SONATYPE_PASSWORD: op://opensearch-infra-secrets/maven-central-portal-credentials/password
49+
MAVEN_SNAPSHOTS_S3_REPO: op://opensearch-infra-secrets/maven-snapshots-s3/repo
50+
MAVEN_SNAPSHOTS_S3_ROLE: op://opensearch-infra-secrets/maven-snapshots-s3/role
51+
52+
- name: Export SNAPSHOT_REPO_URL
53+
run: |
54+
snapshot_repo_url=${{ env.MAVEN_SNAPSHOTS_S3_REPO }}
55+
echo "SNAPSHOT_REPO_URL=$snapshot_repo_url" >> $GITHUB_ENV
56+
57+
- name: Configure AWS credentials
58+
uses: aws-actions/configure-aws-credentials@v5
59+
with:
60+
role-to-assume: ${{ env.MAVEN_SNAPSHOTS_S3_ROLE }}
61+
aws-region: us-east-1
5262

5363
- name: Set commit ID
5464
id: set_commit
@@ -83,4 +93,4 @@ jobs:
8393
source ./.github/maven-publish-utils.sh
8494
8595
# Call the main function for async-query-core
86-
publish_async_query_core "${{ steps.extract_version.outputs.VERSION }}" "${{ steps.set_commit.outputs.commit_id }}"
96+
publish_async_query_core "${{ steps.extract_version.outputs.VERSION }}" "${{ steps.set_commit.outputs.commit_id }}"

.github/workflows/publish-grammar-files.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ on:
55
push:
66
branches:
77
- main
8-
- 1.*
9-
- 2.*
8+
- '[0-9]+.[0-9]+'
9+
- '[0-9]+.x'
1010
paths:
1111
- 'language-grammar/src/main/antlr4/**'
1212
- 'language-grammar/build.gradle'
@@ -19,7 +19,6 @@ concurrency:
1919
cancel-in-progress: false
2020

2121
env:
22-
SNAPSHOT_REPO_URL: https://central.sonatype.com/repository/maven-snapshots/
2322
COMMIT_MAP_FILENAME: commit-history-language-grammar.json
2423

2524
jobs:
@@ -51,8 +50,19 @@ jobs:
5150
export-env: true
5251
env:
5352
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
54-
SONATYPE_USERNAME: op://opensearch-infra-secrets/maven-central-portal-credentials/username
55-
SONATYPE_PASSWORD: op://opensearch-infra-secrets/maven-central-portal-credentials/password
53+
MAVEN_SNAPSHOTS_S3_REPO: op://opensearch-infra-secrets/maven-snapshots-s3/repo
54+
MAVEN_SNAPSHOTS_S3_ROLE: op://opensearch-infra-secrets/maven-snapshots-s3/role
55+
56+
- name: Export SNAPSHOT_REPO_URL
57+
run: |
58+
snapshot_repo_url=${{ env.MAVEN_SNAPSHOTS_S3_REPO }}
59+
echo "SNAPSHOT_REPO_URL=$snapshot_repo_url" >> $GITHUB_ENV
60+
61+
- name: Configure AWS credentials
62+
uses: aws-actions/configure-aws-credentials@v5
63+
with:
64+
role-to-assume: ${{ env.MAVEN_SNAPSHOTS_S3_ROLE }}
65+
aws-region: us-east-1
5666

5767
- name: Set version
5868
id: set_version

DEVELOPER_GUIDE.rst

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ Here are other files and sub-folders that you are likely to touch:
173173
- ``build.gradle``: Gradle build script.
174174
- ``docs``: documentation for developers and reference manual for users.
175175
- ``doc-test``: code that run .rst docs in ``docs`` folder by Python doctest library.
176-
- ``language-grammar``: centralized package for ANTLR grammar files. See `Language Grammar Package`_ for details.
177176

178177
Note that other related project code has already merged into this single repository together:
179178

@@ -444,29 +443,3 @@ with an appropriate label `backport <backport-branch-name>` is merged to main wi
444443
PR. For example, if a PR on main needs to be backported to `1.x` branch, add a label `backport 1.x` to the PR and make sure the
445444
backport workflow runs on the PR along with other checks. Once this PR is merged to main, the workflow will create a backport PR
446445
to the `1.x` branch.
447-
448-
Language Grammar Package
449-
========================
450-
451-
The ``language-grammar`` package serves as a centralized repository for all ANTLR grammar files used throughout the OpenSearch SQL project. This package contains the definitive versions of grammar files for:
452-
453-
- SQL parsing (``OpenSearchSQLParser.g4``, ``OpenSearchSQLLexer.g4``)
454-
- PPL parsing (``OpenSearchPPLParser.g4``, ``OpenSearchPPLLexer.g4``)
455-
- Legacy SQL parsing (``OpenSearchLegacySqlParser.g4``, ``OpenSearchLegacySqlLexer.g4``)
456-
- Spark SQL extensions (``SparkSqlBase.g4``, ``FlintSparkSqlExtensions.g4``, ``SqlBaseParser.g4``, ``SqlBaseLexer.g4``)
457-
458-
Purpose
459-
-------
460-
461-
The language-grammar package enables sharing of grammar files between the main SQL repository and the Spark repository, ensuring consistency and reducing duplication. Once updated, the package automatically triggers CI to upload the new version to Maven Central for consumption by other projects.
462-
463-
Updating Grammar Files
464-
----------------------
465-
466-
When grammar files are modified in their respective modules (``sql/``, ``ppl/``, ``legacy/``, ``async-query-core/``), they must be manually copied to the ``language-grammar/src/main/antlr4/`` directory.
467-
468-
**Workflow:**
469-
470-
1. Modify grammar files in their source locations (e.g., ``sql/src/main/antlr/``)
471-
2. Copy updated files to ``language-grammar/src/main/antlr4/``
472-
3. Commit changes to trigger automatic Maven publication via CI

api/README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Unified Query API
2+
3+
This module provides a high-level integration layer for the Calcite-based query engine, enabling external systems such as Apache Spark or command-line tools to parse and analyze queries without exposing low-level internals.
4+
5+
## Overview
6+
7+
The `UnifiedQueryPlanner` serves as the primary entry point for external consumers. It accepts PPL (Piped Processing Language) queries and returns Calcite `RelNode` logical plans as intermediate representation.
8+
9+
## Usage
10+
11+
Use the declarative, fluent builder API to initialize the `UnifiedQueryPlanner`.
12+
13+
```java
14+
UnifiedQueryPlanner planner = UnifiedQueryPlanner.builder()
15+
.language(QueryType.PPL)
16+
.catalog("opensearch", schema)
17+
.defaultNamespace("opensearch")
18+
.cacheMetadata(true)
19+
.build();
20+
21+
RelNode plan = planner.plan("source = opensearch.test");
22+
```
23+
24+
## Development & Testing
25+
26+
A set of unit tests is provided to validate planner behavior.
27+
28+
To run tests:
29+
30+
```
31+
./gradlew :api:test
32+
```
33+
34+
## Integration Guide
35+
36+
This guide walks through how to integrate unified query planner into your application.
37+
38+
### Step 1: Add Dependency
39+
40+
The module is currently published as a snapshot to the AWS Sonatype Snapshots repository. To include it as a dependency in your project, add the following to your `pom.xml` or `build.gradle`:
41+
42+
```xml
43+
<dependency>
44+
<groupId>org.opensearch.query</groupId>
45+
<artifactId>unified-query-api</artifactId>
46+
<version>YOUR_VERSION_HERE</version>
47+
</dependency>
48+
```
49+
50+
### Step 2: Implement a Calcite Schema
51+
52+
You must implement the Calcite `Schema` interface and register them using the fluent `catalog()` method on the builder.
53+
54+
```java
55+
public class MySchema extends AbstractSchema {
56+
@Override
57+
protected Map<String, Table> getTableMap() {
58+
return Map.of(
59+
"test_table",
60+
new AbstractTable() {
61+
@Override
62+
public RelDataType getRowType(RelDataTypeFactory typeFactory) {
63+
return typeFactory.createStructType(
64+
List.of(typeFactory.createSqlType(SqlTypeName.INTEGER)),
65+
List.of("id"));
66+
}
67+
});
68+
}
69+
}
70+
```
71+
72+
## Future Work
73+
74+
- Expand support to SQL language.
75+
- Extend planner to generate optimized physical plans using Calcite's optimization frameworks.

api/build.gradle

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
plugins {
7+
id 'java-library'
8+
id 'jacoco'
9+
id 'com.diffplug.spotless'
10+
}
11+
12+
dependencies {
13+
api project(':ppl')
14+
15+
testImplementation group: 'junit', name: 'junit', version: '4.13.2'
16+
testImplementation group: 'org.hamcrest', name: 'hamcrest-library', version: "${hamcrest_version}"
17+
testImplementation group: 'org.mockito', name: 'mockito-core', version: "${mockito_version}"
18+
testImplementation group: 'org.apache.calcite', name: 'calcite-testkit', version: '1.38.0'
19+
}
20+
21+
spotless {
22+
java {
23+
target fileTree('.') {
24+
include '**/*.java'
25+
exclude '**/build/**', '**/build-*/**', 'src/main/gen/**'
26+
}
27+
importOrder()
28+
removeUnusedImports()
29+
trimTrailingWhitespace()
30+
endWithNewline()
31+
googleJavaFormat('1.17.0').reflowLongStrings().groupArtifact('com.google.googlejavaformat:google-java-format')
32+
}
33+
}
34+
35+
test {
36+
testLogging {
37+
events "passed", "skipped", "failed"
38+
exceptionFormat "full"
39+
}
40+
}
41+
42+
jacocoTestReport {
43+
reports {
44+
html.required = true
45+
xml.required = true
46+
}
47+
afterEvaluate {
48+
classDirectories.setFrom(files(classDirectories.files.collect {
49+
fileTree(dir: it,
50+
exclude: ['**/antlr/parser/**'])
51+
}))
52+
}
53+
}
54+
test.finalizedBy(project.tasks.jacocoTestReport)
55+
jacocoTestCoverageVerification {
56+
violationRules {
57+
rule {
58+
limit {
59+
minimum = 0.9
60+
}
61+
62+
}
63+
}
64+
afterEvaluate {
65+
classDirectories.setFrom(files(classDirectories.files.collect {
66+
fileTree(dir: it,
67+
exclude: ['**/antlr/parser/**'])
68+
}))
69+
}
70+
}
71+
check.dependsOn jacocoTestCoverageVerification

0 commit comments

Comments
 (0)