Skip to content

Add FROM-first query syntax support#17410

Merged
JackieTien97 merged 3 commits intoapache:masterfrom
Abdelrahman-358:f_from_first_syntax
Apr 8, 2026
Merged

Add FROM-first query syntax support#17410
JackieTien97 merged 3 commits intoapache:masterfrom
Abdelrahman-358:f_from_first_syntax

Conversation

@Abdelrahman-358
Copy link
Copy Markdown
Contributor

@Abdelrahman-358 Abdelrahman-358 commented Mar 31, 2026

Description

This PR implements support for the feature proposed in #17336 by introducing FROM-first query syntax.

Usage Examples

-- Current syntax
SELECT temperature, humidity FROM sensors WHERE time >= 10;

-- FROM-first syntax
FROM sensors SELECT temperature, humidity WHERE time >= 10;

-- Quick exploration (omitting SELECT implies SELECT *)
FROM sensors LIMIT 10;

Implementation Approach

  1. Grammar Update
    Add fromFirstQuerySpecification rule to RelationalSql.g4.

  2. AST Builder
    Add visitFromFirstQuerySpecification() in AstBuilder.java, reusing the existing visitQuerySpecification() logic, with handling for the omitted SELECT clause (interpreted as SELECT *).

  3. Testing
    Add unit and integration tests to cover the new syntax scenarios.


This PR has:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • added Javadocs for most classes and all non-trivial methods.
  • added or updated version, license, or notice information
  • added comments explaining the "why" and the intent of the code wherever would not be obvious
    for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold
    for code coverage.
  • added integration tests.
  • been tested in a test IoTDB cluster.

Key changed/added classes (or packages if there are too many classes) in this PR

@Abdelrahman-358 Abdelrahman-358 marked this pull request as draft March 31, 2026 15:52
@Abdelrahman-358 Abdelrahman-358 marked this pull request as ready for review April 4, 2026 00:47
@Abdelrahman-358
Copy link
Copy Markdown
Contributor Author

Hi @JackieTien97 , could you please review this PR when you have time?

I’ve also sent a request to the dev mailing list, but it may have been filtered into the Promotions tab.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an additional, DuckDB-style FROM-first query form to IoTDB’s relational SQL dialect, enabling FROM <table> [SELECT ...] ... (with omitted SELECT implying SELECT *) while preserving existing SELECT-first syntax.

Changes:

  • Extend the ANTLR grammar to parse FROM-first query specifications as a queryPrimary.
  • Add AST builder support to translate FROM-first parse trees into the existing QuerySpecification AST (including implicit SELECT *).
  • Add analyzer-level unit tests and a new integration test suite covering basic queries, implicit select, joins, and aggregation.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
iotdb-core/relational-grammar/src/main/antlr4/org/apache/iotdb/db/relational/grammar/sql/RelationalSql.g4 Adds fromFirstQuerySpecification and wires it into queryPrimary so queries can start with FROM.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java Builds a QuerySpecification from the new grammar rule, including implicit SELECT * behavior.
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/AnalyzerTest.java Adds unit tests to ensure FROM-first queries analyze/plan equivalently to SELECT-first equivalents.
integration-test/src/test/java/org/apache/iotdb/relational/it/query/recent/IoTDBFromFirstQueryIT.java Adds integration coverage for end-to-end execution of FROM-first queries across common patterns.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@JackieTien97 JackieTien97 merged commit 2e77bf4 into apache:master Apr 8, 2026
24 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants