-
Notifications
You must be signed in to change notification settings - Fork 153
Unified OpenSearch PPL Data Type #3345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c70a069
Unified PPL data type
penghuo 6cf74f4
Fix doctest
penghuo 7e381d5
Update doc
penghuo d5412a9
fix integ-test
penghuo 4926dc4
update spot
penghuo e2da843
Fix UT
penghuo bd20fc1
Merge branch 'main' into issue3339
penghuo 516c9b3
Fix SystemFunctionIT
penghuo d21eb64
Update IT
penghuo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.lang; | ||
|
||
import static org.opensearch.sql.executor.QueryType.PPL; | ||
|
||
import org.opensearch.sql.data.type.ExprType; | ||
import org.opensearch.sql.executor.QueryType; | ||
|
||
/** | ||
* Represents a language specification for query processing. | ||
* | ||
* <p>This interface defines basic methods for language-specific behaviors, such as determining the | ||
* language type and mapping expression types to type names. Two language specifications are | ||
* provided: SQL and PPL. | ||
*/ | ||
public interface LangSpec { | ||
|
||
/** The default SQL language specification instance. */ | ||
LangSpec SQL_SPEC = new LangSpec() {}; | ||
|
||
/** | ||
* Returns a language specification instance based on the provided language name. | ||
* | ||
* @param language the name of the language, case-insensitive. | ||
* @return the PPL language specification if the language is PPL (ignoring case); otherwise, the | ||
* SQL language specification. | ||
*/ | ||
static LangSpec fromLanguage(String language) { | ||
if (PPL.name().equalsIgnoreCase(language)) { | ||
return PPLLangSpec.PPL_SPEC; | ||
} else { | ||
return SQL_SPEC; | ||
} | ||
} | ||
|
||
/** | ||
* Returns the language type of this specification. | ||
* | ||
* <p>By default, the language is considered SQL. | ||
* | ||
* @return the language type, SQL by default. | ||
*/ | ||
default QueryType language() { | ||
return QueryType.SQL; | ||
} | ||
|
||
/** | ||
* Returns the type name for the given expression type. | ||
* | ||
* <p>This default implementation returns the result of {@code exprType.typeName()}. | ||
* | ||
* @param exprType the expression type. | ||
* @return the type name of the expression. | ||
*/ | ||
default String typeName(ExprType exprType) { | ||
return exprType.typeName(); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
core/src/main/java/org/opensearch/sql/lang/PPLLangSpec.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.lang; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.opensearch.sql.data.type.ExprCoreType; | ||
import org.opensearch.sql.data.type.ExprType; | ||
import org.opensearch.sql.executor.QueryType; | ||
|
||
/** | ||
* PPL language specification implementation. | ||
* | ||
* <p>This class provides a singleton implementation of {@link LangSpec} for PPL. It defines a | ||
* custom mapping from expression types to PPL type names. | ||
*/ | ||
public class PPLLangSpec implements LangSpec { | ||
|
||
public static final PPLLangSpec PPL_SPEC = new PPLLangSpec(); | ||
|
||
private static Map<ExprType, String> exprTypeToPPLType = new HashMap<>(); | ||
|
||
static { | ||
exprTypeToPPLType.put(ExprCoreType.BYTE, "tinyint"); | ||
exprTypeToPPLType.put(ExprCoreType.SHORT, "smallint"); | ||
exprTypeToPPLType.put(ExprCoreType.INTEGER, "int"); | ||
exprTypeToPPLType.put(ExprCoreType.LONG, "bigint"); | ||
} | ||
|
||
private PPLLangSpec() {} | ||
|
||
@Override | ||
public QueryType language() { | ||
return QueryType.PPL; | ||
} | ||
|
||
/** | ||
* Returns the corresponding PPL type name for the given expression type. If the expression type | ||
* is not mapped, it returns the default type name. | ||
* | ||
* @param exprType the expression type. | ||
* @return the PPL type name associated with the expression type, or the default type name. | ||
*/ | ||
@Override | ||
public String typeName(ExprType exprType) { | ||
return exprTypeToPPLType.getOrDefault(exprType, exprType.typeName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a breaking change, why don't we directly change the old type to the new type, instead of introducing
LangSpec
? Isn't this unnecessarily adding complexity?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. The core type was not upgraded because I intended for the data type changes to affect only PPL and not SQL. This PR focuses on unifying PPL data types, while SQL data types can be addressed in a separate issue, as changes there would impact JDBC, ODBC, and CLI.
Ideally, the query engine should use well-defined data types, with LangSpec serving as the protocol for translating these engine types to language-specific types. Once the Calcite implementation is complete, CalciteDataType will translate to ExprDataType, and LangSpec will translate from ExprDataType to the PPL response data type.