Skip to content

[FEATURE] Make OpenSearch function registered dynamically #811

Closed as not planned

Description

@dai-chen

Is your feature request related to a problem?
Currently all OpenSearch functions are "hardcoded" in ANTLR grammar file. As external storage like S3 and Prometheus added, this will cause problem. For example, in current implementation, query like "... FROM s3.logs WHERE QUERY_STRING(...)" can pass ANTLR parser but fail at execution time due to missing QUERY_STRING function support in S3 storage.

What solution would you like?
One approach is each storage engine registers specific function dynamically when plugin bootstraps. The ANTLR grammar only includes common ANSI SQL functions that has in-memory implementation along with a new udf rule that match unrecognized functions as User-Defined Function. Later analyzer can verify if the UDF is valid or not. This approach naturally provides UDF support for future.

What alternatives have you considered?
N/A

Do you have any additional context?
N/A

Activity

  1. added
    enhancement
    on Sep 8, 2022
  2. MaxKsyunz commented on Sep 10, 2022

    @MaxKsyunz
    Collaborator

    @dai-chen, v1 engine supports this syntax for relevance queries -- SELECT * FROM index WHERE field = match("string").

    If we add it to v2 engine, this feature would need to support this syntax as well. Especially given #787.

  3. dai-chen commented on Sep 12, 2022

    @dai-chen
    CollaboratorAuthor

    @dai-chen, v1 engine supports this syntax for relevance queries -- SELECT * FROM index WHERE field = match("string").

    If we add it to v2 engine, this feature would need to support this syntax as well. Especially given #787.

    Sure, we need to figure out a general way and allow each storage engine to register specific data type and function dynamically. Earlier our storage engine interface was referencing Apache Calcite. Probably we can explore further here: https://github.com/apache/calcite/blob/main/core/src/main/java/org/apache/calcite/schema/Schema.java

  4. added
    maintenance
    and removed
    enhancement
    on Oct 31, 2022
  5. added
    legacy
    and removed
    legacy
    on Nov 16, 2022
  6. biggoon commented on Nov 23, 2022

    @biggoon

    Another think to add: we need to move the analyzers relevant to the user-defined functions (such as the HighlightAnalyzer) out of core and inject them into the Analyzer dynamically.
    see: https://github.com/opensearch-project/sql/blob/2.x/core/src/main/java/org/opensearch/sql/analysis/Analyzer.java#L364

  7. dai-chen commented on Nov 23, 2022

    @dai-chen
    CollaboratorAuthor

    Another think to add: we need to move the analyzers relevant to the user-defined functions (such as the HighlightAnalyzer) out of core and inject them into the Analyzer dynamically. see: https://github.com/opensearch-project/sql/blob/2.x/core/src/main/java/org/opensearch/sql/analysis/Analyzer.java#L364

    That'd great be if we can do that for highlight as well. I've met this problem with highlight operator when refactor optimizer: https://github.com/opensearch-project/sql/pull/1091/files#diff-3334dc7821335d1c35cb35e3da00960106b6ac04c4ca092937c51c076056d272R103. I have to add a pushDownHighlight rule, however there is no fallback if push down not happen on other storage like S3/Prometheus. There is no in-memory implementation and highlight maybe only make sense for OpenSearch storage.

  8. acarbonetto commented on Jun 13, 2023

    @acarbonetto
    Collaborator

    @acarbonetto create issue to determine if we can split work up into the following:

    • PoC to split out an OpenSearch-specific function (like match) from the core ANTLR parser into a UDF-like function defined by the OpenSearch storage engine (vamsi has done this for promises and can be linked).
    • Second ticket to scope out the parser refactor and create follow-up tickets for related work.
    • For core refactor, define follow-up activities to determine other core classes that have OpenSearch-specific operations that should be moved to the OpenSearch module.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority-Highmaintenance

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions