Skip to content
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

[v1] Add .valueOf and .values methods for enums #1628

Merged
merged 2 commits into from
Oct 25, 2024

Conversation

alancai98
Copy link
Member

Relevant Issues

Description

  • The previous sprout-generated code used Kotlin enum classes which provided some helper methods when working with enum constants -- https://kotlinlang.org/docs/enum-classes.html#working-with-enum-constants. I found I needed these in the partiql-parser migration, particularly .valueOf(<string>) and .values. This PR adds those two functions to the interface and implements them for existing enum impls.

Other Information

  • Updated Unreleased Section in CHANGELOG: [NO]

    • No, on v1.
  • Any backward-incompatible changes? [YES]

    • Adds to the enum interface but on v1
  • Any new external dependencies? [NO]

  • Do your changes comply with the Contributing Guidelines
    and Code Style Guidelines? [YES]

License Information

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@alancai98 alancai98 self-assigned this Oct 22, 2024
@codecov-commenter
Copy link

codecov-commenter commented Oct 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (v1-migrate-ast-eq-hc@34a0993). Learn more about missing BASE report.

Additional details and impacted files
@@                   Coverage Diff                   @@
##             v1-migrate-ast-eq-hc    #1628   +/-   ##
=======================================================
  Coverage                        ?   80.03%           
  Complexity                      ?       47           
=======================================================
  Files                           ?       19           
  Lines                           ?      506           
  Branches                        ?       23           
=======================================================
  Hits                            ?      405           
  Misses                          ?       88           
  Partials                        ?       13           
Flag Coverage Δ
EXAMPLES 80.03% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

github-actions bot commented Oct 22, 2024

CROSS-ENGINE-REPORT ❌

BASE (LEGACY-V0.14.8) TARGET (EVAL-3E005DC) +/-
% Passing 89.67% 94.39% 4.72% ✅
Passing 5287 5565 278 ✅
Failing 609 50 -559 ✅
Ignored 0 281 281 🔶
Total Tests 5896 5896 0 ✅

Testing Details

  • Base Commit: v0.14.8
  • Base Engine: LEGACY
  • Target Commit: 3e005dc
  • Target Engine: EVAL

Result Details

  • ❌ REGRESSION DETECTED. See Now Failing/Ignored Tests. ❌
  • Passing in both: 2643
  • Failing in both: 17
  • Ignored in both: 0
  • PASSING in BASE but now FAILING in TARGET: 3
  • PASSING in BASE but now IGNORED in TARGET: 108
  • FAILING in BASE but now PASSING in TARGET: 180
  • IGNORED in BASE but now PASSING in TARGET: 0

Now FAILING Tests ❌

The following 3 test(s) were previously PASSING in BASE but are now FAILING in TARGET:

Click here to see
  1. undefinedUnqualifiedVariableWithUndefinedVariableBehaviorMissing, compileOption: PERMISSIVE
  2. undefinedUnqualifiedVariableIsNullExprWithUndefinedVariableBehaviorMissing, compileOption: PERMISSIVE
  3. undefinedUnqualifiedVariableIsMissingExprWithUndefinedVariableBehaviorMissing, compileOption: PERMISSIVE

Now IGNORED Tests ❌

The complete list can be found in GitHub CI summary, either from Step Summary or in the Artifact.

Now Passing Tests

180 test(s) were previously failing in BASE (LEGACY-V0.14.8) but now pass in TARGET (EVAL-3E005DC). Before merging, confirm they are intended to pass.

The complete list can be found in GitHub CI summary, either from Step Summary or in the Artifact.

CROSS-COMMIT-REPORT ✅

BASE (EVAL-03905DB) TARGET (EVAL-3E005DC) +/-
% Passing 94.39% 94.39% 0.00% ✅
Passing 5565 5565 0 ✅
Failing 50 50 0 ✅
Ignored 281 281 0 ✅
Total Tests 5896 5896 0 ✅

Testing Details

  • Base Commit: 03905db
  • Base Engine: EVAL
  • Target Commit: 3e005dc
  • Target Engine: EVAL

Result Details

  • Passing in both: 5565
  • Failing in both: 50
  • Ignored in both: 281
  • PASSING in BASE but now FAILING in TARGET: 0
  • PASSING in BASE but now IGNORED in TARGET: 0
  • FAILING in BASE but now PASSING in TARGET: 0
  • IGNORED in BASE but now PASSING in TARGET: 0

@alancai98 alancai98 force-pushed the v1-migrate-ast-enum-methods branch 3 times, most recently from 215dc30 to bb30367 Compare October 22, 2024 23:20
@@ -1,6 +1,7 @@
package org.partiql.ast.v1;

import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;

@EqualsAndHashCode(callSuper = false)
public class DataType implements Enum {
Copy link
Member Author

Choose a reason for hiding this comment

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

for every AST class implementing the enum interface, added the valueOf(String value) and values() static methods

case "TIMESTAMP_WITH_TIME_ZONE": return TIMESTAMP_WITH_TIME_ZONE();
case "INTERVAL": return INTERVAL();
case "USER_DEFINED": return USER_DEFINED();
default: return UNKNOWN();
Copy link
Member Author

Choose a reason for hiding this comment

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

unidentified string values will map to UNKNOWN

Copy link
Contributor

Choose a reason for hiding this comment

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

this is a good example of the backwards compatibility

}
}

public static DataType[] values() {
Copy link
Member Author

Choose a reason for hiding this comment

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

.values() does not include UNKNOWN

@alancai98 alancai98 marked this pull request as ready for review October 23, 2024 21:56
@alancai98
Copy link
Member Author

Other changes I'll make from offline discussion:

  1. Change naming of Enum to AstEnum
  2. Change AstEnum to be an abstract class that extends AstNode. AstNode will still be an abstract class since it has state (i.e. the tag)
  3. Change static method values() to be named codes() and return an array of ints
  4. Change static method valueOf(String value) to be named parse(String value). Still will return the enum class.

Base automatically changed from v1-migrate-ast-eq-hc to v1 October 24, 2024 23:45
case "TIMESTAMP_WITH_TIME_ZONE": return TIMESTAMP_WITH_TIME_ZONE();
case "INTERVAL": return INTERVAL();
case "USER_DEFINED": return USER_DEFINED();
default: return UNKNOWN();
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a good example of the backwards compatibility

@alancai98 alancai98 merged commit 7f382db into v1 Oct 25, 2024
14 checks passed
@alancai98 alancai98 deleted the v1-migrate-ast-enum-methods branch October 25, 2024 16:45
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