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

CURRENT_USER, 'USER and SESSION_USER` system functions #5807

Merged
merged 1 commit into from
Jul 5, 2017

Conversation

andreidan
Copy link
Contributor

No description provided.

@@ -232,6 +232,9 @@ primaryExpression
| name=CURRENT_TIME ('(' precision=integerLiteral')')? #specialDateTimeFunction
| name=CURRENT_TIMESTAMP ('(' precision=integerLiteral')')? #specialDateTimeFunction
| CURRENT_SCHEMA ('(' ')')? #currentSchema
| CURRENT_USER #currentUser
| USER #user
Copy link
Contributor

Choose a reason for hiding this comment

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

if USER is always returning CURRENT_USER they can be merged in the same statement | (CURRENT_USER | USER) #currentUser and visitUser won't be needed

@andreidan andreidan force-pushed the andrei/userFunctions branch 2 times, most recently from 6edf4e7 to abb059a Compare June 26, 2017 13:15
@andreidan andreidan requested a review from seut June 26, 2017 13:18
``USER``
--------

Equivalent to ``CURRENT_USER``.
Copy link
Member

Choose a reason for hiding this comment

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

pls make CURRENT_USER a reference(link) (use `CURRENT_USER`_)


``SESSION_USER``
----------------
The ``SESSION_USER`` system information function returns the name of the
Copy link
Member

Choose a reason for hiding this comment

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

missing newline

Copy link
Member

Choose a reason for hiding this comment

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

why is the description here explicit (but a copy of CURRENT_USER) instead of the same description of USER?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because SESSION_USER is not the same as CURRENT_USER. See the difference in result column name.


.. note::

The ``CURRENT_USER``, ``SESSION_USER`` and ``USER`` functions have a
Copy link
Member

Choose a reason for hiding this comment

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

pls make all 3 links

@@ -1647,4 +1719,7 @@ Example::
.. _Java Regular Expressions: http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html
.. _`MySQL date_format`: http://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html#function_date-format
.. _`Haversine formula`: https://en.wikipedia.org/wiki/Haversine_formula

Copy link
Member

Choose a reason for hiding this comment

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

pls remove all these new lines

@@ -232,6 +232,8 @@ primaryExpression
| name=CURRENT_TIME ('(' precision=integerLiteral')')? #specialDateTimeFunction
| name=CURRENT_TIMESTAMP ('(' precision=integerLiteral')')? #specialDateTimeFunction
| CURRENT_SCHEMA ('(' ')')? #currentSchema
| (CURRENT_USER | USER) #currentUser
| SESSION_USER ('(' ')')? #sessionUser
Copy link
Member

Choose a reason for hiding this comment

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

the documentation does not mention optional parenthesis

import javax.annotation.Nullable;


public class SessionUserFunction extends Scalar<BytesRef, Object> implements FunctionFormatSpec {
Copy link
Member

Choose a reason for hiding this comment

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

this class is a complete copy of CurrentUserFunction. pls solve by 1 implementation which is registered under 2 different names

}

static Symbol normalizeUsernameFor(String functionName, @Nullable TransactionContext transactionContext) {
if (transactionContext == null) {
Copy link
Member

Choose a reason for hiding this comment

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

move inside your function after you have refactored it to 1 implementation

@@ -350,12 +350,12 @@ public void testCreateTableWithAnalyzerParameter() throws Exception {
public void textCreateTableWithCustomAnalyzerInNestedColumn() throws Exception {
CreateTableAnalyzedStatement analysis = e.analyze(
"create table ft_search (" +
"user object (strict) as (" +
"auser object (strict) as (" +
Copy link
Member

Choose a reason for hiding this comment

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

why not just quote the user? would make it much more readable

Copy link
Contributor Author

@andreidan andreidan Jun 27, 2017

Choose a reason for hiding this comment

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

I thought " "user" object" is actually less readable than "auser object"

@@ -215,24 +215,24 @@ public void testShowCreateTableWithGeneratedColumn() throws Exception {
" col1 AS ts + 1," +
" col2 string GENERATED ALWAYS AS ts + 1," +
" col3 string GENERATED ALWAYS AS (ts + 1)," +
" name AS concat(user['name'], 'foo')," +
Copy link
Member

Choose a reason for hiding this comment

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

just quote the user and nothing else needs to be changed...

import static io.crate.testing.SymbolMatchers.isLiteral;
import static org.hamcrest.core.Is.is;

public class UserFunctionsNormalizerTest extends CrateUnitTest {
Copy link
Member

Choose a reason for hiding this comment

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

pls move all tests to UserFunctionsTest after your refactoring

Copy link
Member

@seut seut left a comment

Choose a reason for hiding this comment

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

lgtm otherwise

this.functionInfo = new FunctionInfo(new FunctionIdent(name, ImmutableList.of()), DataTypes.STRING);
}

public static void register(ScalarFunctionModule scalarFunctionModule) {
Copy link
Member

Choose a reason for hiding this comment

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

pls define before all instance vars and methods

@andreidan andreidan force-pushed the andrei/userFunctions branch 2 times, most recently from 6591525 to d70c201 Compare June 28, 2017 11:38
public void testNormalizeUser() {
assertNormalize("user", isLiteral("testUser"), false);
}
}
Copy link
Member

Choose a reason for hiding this comment

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

please also test the case where the user isn't set on the session

Copy link
Member

@mfussenegger mfussenegger left a comment

Choose a reason for hiding this comment

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

please also test the case where the user isn't set on the session

username = user.name();
if (user == null) {
throw new UnsupportedFeatureException(
String.format(Locale.ENGLISH, "%s function is only supported in enterprise version", name)
Copy link
Member

Choose a reason for hiding this comment

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

hm but it also can be null if the user management is disabled...

@codecov-io
Copy link

codecov-io commented Jun 28, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@31fba78). Click here to learn what that means.
The diff coverage is 82.35%.

Impacted file tree graph

@@           Coverage Diff            @@
##             master   #5807   +/-   ##
========================================
  Coverage          ?   83.1%           
  Complexity        ?   12201           
========================================
  Files             ?    1428           
  Lines             ?   46642           
  Branches          ?    5754           
========================================
  Hits              ?   38764           
  Misses            ?    5209           
  Partials          ?    2669
Impacted Files Coverage Δ Complexity Δ
...o/crate/operation/scalar/ScalarFunctionModule.java 100% <ø> (ø) 6 <0> (?)
.../src/main/java/io/crate/sql/parser/AstBuilder.java 94.11% <100%> (ø) 243 <2> (?)
...ava/io/crate/scalar/UsersScalarFunctionModule.java 100% <100%> (ø) 2 <2> (?)
...ers/src/main/java/io/crate/plugin/UsersPlugin.java 100% <100%> (ø) 7 <3> (?)
...o/crate/scalar/systeminformation/UserFunction.java 68.42% <68.42%> (ø) 8 <8> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 31fba78...09f6240. Read the comment docs.

Copy link
Member

@mfussenegger mfussenegger left a comment

Choose a reason for hiding this comment

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

Can't we change it to always just return null if the user isn't available in the session and get rid of these enterprise checks?

@andreidan
Copy link
Contributor Author

@mfussenegger Discussed with @dobe to throw UnsupportedFeatureException as it's an enterprise feature (to be consistent with CREATE/DROP USER)

@andreidan andreidan force-pushed the andrei/userFunctions branch 4 times, most recently from f8de716 to 3ff4b32 Compare July 5, 2017 11:32
@andreidan andreidan merged commit 09f6240 into master Jul 5, 2017
@andreidan andreidan deleted the andrei/userFunctions branch July 5, 2017 12:30
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.

None yet

5 participants