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

feat: new syntax to interact with session variables (define/undefine/show variables) #6474

Merged
merged 3 commits into from
Oct 22, 2020

Conversation

spena
Copy link
Member

@spena spena commented Oct 20, 2020

Description

This is part of KLIP-38 - Variable Substitution
Variable substitution will have a follow-up PR.

It adds a syntax to interact with session variables:

  • DEFINE = '';
  • UNDEFINE ;
  • (LIST | SHOW) VARIABLES
    ^ The KLIP proposed the use of DEFINE to list values. But I saw the SHOW more appropriate as we have SHOW and LIST syntax for other entities. I will change the KLIP after variable substitution is merged.

The syntax is added on the server-side and CLI-side.

For the server-side, the variable scope is seen per-request. i.e.

Request 1 will return the variables `x` and `y`.
{ 
  statement: "
    DEFINE x = '1';
    DEFINE y = '2';
    SHOW VARIABLES;
  "
}

Request 2 will return the variables `z`.
{ 
  statement: "
    DEFINE z = '3';
    SHOW VARIABLES;
  "
}

For the CLI-side, the variable scope is during the session of the CLI. i.e.

ksql> DEFINE x = '1';
ksql> DEFINE y = '2';
ksql> SHOW VARIABLES;
 Variable Name | Value 
-----------------------
 x             | 1     
 y             | 2     
-----------------------
ksql> DEFINE z = '3';
ksql> SHOW VARIABLES;
 Variable Name | Value 
-----------------------
 x             | 1     
 y             | 2     
 z             | 3     
-----------------------

Testing done

Added unit tests
Verified manually (see above examples)

Reviewer checklist

  • Ensure docs are updated if necessary. (eg. if a user visible feature is being added or changed).
  • Ensure relevant issues are linked (description should include text like "Fixes #")

@spena spena requested a review from a team October 20, 2020 17:59
Copy link
Contributor

@agavra agavra left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -566,6 +581,10 @@ TIMESTAMP_WITH_TIME_ZONE
: 'TIMESTAMP' WS 'WITH' WS 'TIME' WS 'ZONE'
;

VARIABLE
Copy link
Contributor

Choose a reason for hiding this comment

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

is this used anywhere for this PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

No in this PR. I used it initially, but after splitting the PR I left it by accident.

I will leave it here. The next PR will use it anyway, so doesn't hurt.

@RunWith(MockitoJUnitRunner.class)
public class ListVariablesExecutorTest {
@Rule
public final TemporaryEngine engine = new TemporaryEngine();
Copy link
Contributor

Choose a reason for hiding this comment

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

do you need to actually run through configure etc... or can you mock out the configured statements?

Copy link
Member Author

Choose a reason for hiding this comment

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

I copied most of the code from ListTopicsExecutorTest and ListPropertiesExecutorTest. But you're right, we don't need this engine. I'll change it with a mock.

}

@Test
public void shouldThrowOnInvalidValues() {
Copy link
Contributor

Choose a reason for hiding this comment

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

should we add a test on adding duplicates? we should also check to make sure that case insensitive duplicates are stilled rejected

Copy link
Member Author

Choose a reason for hiding this comment

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

Variables will be overridden (no rejected) if an existing case insensitive variable exists. I'll add a test case that verifies that.

It will allow us to do this:

DEFINE var1 = '1';
DEFINE VAR1 = '2';
DEFINE vAr1 = '3'; // latest update

@spena spena force-pushed the define_session_variables branch from ac1b0df to ec1c89d Compare October 22, 2020 11:26
@spena spena force-pushed the define_session_variables branch from ec1c89d to a9a9ba8 Compare October 22, 2020 17:59
@spena spena merged commit df98ef4 into confluentinc:master Oct 22, 2020
@spena spena deleted the define_session_variables branch October 22, 2020 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants