-
Notifications
You must be signed in to change notification settings - Fork 187
feat: Implement PPL convert command with 5 conversion functions #5157
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
base: main
Are you sure you want to change the base?
Changes from all commits
1168a32
d5606bf
67ddf4f
3cb1fa3
66a23d7
b0781cd
6ff9c2a
2f24dba
6763d8f
4e89f18
20f0b16
a5a672b
1bc2c61
a8020f8
c77fdfb
4803558
a2db4e2
0daf0a5
9f69d4d
8658396
bd13675
af71278
78ec131
4561ba8
7f19738
841413d
638c1be
7d5f959
9f61b68
8aa1c61
4b4ca2e
3117082
2733ce7
48312d0
3293010
ac93662
cbe577b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.ast.tree; | ||
|
|
||
| import com.google.common.collect.ImmutableList; | ||
| import java.util.List; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.Setter; | ||
| import lombok.ToString; | ||
| import org.opensearch.sql.ast.AbstractNodeVisitor; | ||
| import org.opensearch.sql.ast.expression.Let; | ||
|
|
||
| /** AST node representing the Convert command. */ | ||
| @Getter | ||
| @Setter | ||
| @ToString | ||
| @EqualsAndHashCode(callSuper = false) | ||
| @RequiredArgsConstructor | ||
| public class Convert extends UnresolvedPlan { | ||
| private final List<Let> conversions; | ||
| private UnresolvedPlan child; | ||
|
|
||
| @Override | ||
| public Convert attach(UnresolvedPlan child) { | ||
| this.child = child; | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public List<UnresolvedPlan> getChild() { | ||
| return this.child == null ? ImmutableList.of() : ImmutableList.of(this.child); | ||
| } | ||
|
|
||
| @Override | ||
| public <T, C> T accept(AbstractNodeVisitor<T, C> nodeVisitor, C context) { | ||
| return nodeVisitor.visitConvert(this, context); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.expression.function.udf; | ||
|
|
||
| /** PPL auto() conversion function. */ | ||
| public class AutoConvertFunction extends BaseConversionUDF { | ||
|
|
||
| private static final AutoConvertFunction INSTANCE = new AutoConvertFunction(); | ||
|
|
||
| public AutoConvertFunction() { | ||
| super(AutoConvertFunction.class); | ||
| } | ||
|
|
||
| public static Object convert(Object value) { | ||
| return INSTANCE.convertValue(value); | ||
| } | ||
|
Comment on lines
+13
to
+19
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add JavaDoc for the public constructor and convert entrypoint. These public methods currently lack JavaDoc with As per coding guidelines: "core/src/main/java/**/*.java: Public methods MUST have JavaDoc with 🤖 Prompt for AI Agents |
||
|
|
||
| @Override | ||
| protected Object applyConversion(String preprocessedValue) { | ||
| Double result = tryConvertMemoryUnit(preprocessedValue); | ||
| if (result != null) { | ||
| return result; | ||
| } | ||
|
|
||
| return NumConvertFunction.INSTANCE.applyConversion(preprocessedValue); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.