-
Notifications
You must be signed in to change notification settings - Fork 549
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
Conversation
b90bd01
to
43d1e4b
Compare
sql-parser/src/main/antlr/SqlBase.g4
Outdated
@@ -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 |
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.
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
6edf4e7
to
abb059a
Compare
blackbox/docs/sql/scalar.txt
Outdated
``USER`` | ||
-------- | ||
|
||
Equivalent to ``CURRENT_USER``. |
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.
pls make CURRENT_USER
a reference(link) (use `CURRENT_USER`_
)
blackbox/docs/sql/scalar.txt
Outdated
|
||
``SESSION_USER`` | ||
---------------- | ||
The ``SESSION_USER`` system information function returns the name of the |
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.
missing newline
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.
why is the description here explicit (but a copy of CURRENT_USER
) instead of the same description of USER
?
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.
Because SESSION_USER
is not the same as CURRENT_USER
. See the difference in result column name.
blackbox/docs/sql/scalar.txt
Outdated
|
||
.. note:: | ||
|
||
The ``CURRENT_USER``, ``SESSION_USER`` and ``USER`` functions have a |
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.
pls make all 3 links
blackbox/docs/sql/scalar.txt
Outdated
@@ -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 | |||
|
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.
pls remove all these new lines
sql-parser/src/main/antlr/SqlBase.g4
Outdated
@@ -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 |
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.
the documentation does not mention optional parenthesis
import javax.annotation.Nullable; | ||
|
||
|
||
public class SessionUserFunction extends Scalar<BytesRef, Object> implements FunctionFormatSpec { |
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.
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) { |
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.
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 (" + |
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.
why not just quote the user? would make it much more readable
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 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')," + |
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.
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 { |
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.
pls move all tests to UserFunctionsTest after your refactoring
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.
lgtm otherwise
this.functionInfo = new FunctionInfo(new FunctionIdent(name, ImmutableList.of()), DataTypes.STRING); | ||
} | ||
|
||
public static void register(ScalarFunctionModule scalarFunctionModule) { |
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.
pls define before all instance vars and methods
6591525
to
d70c201
Compare
public void testNormalizeUser() { | ||
assertNormalize("user", isLiteral("testUser"), false); | ||
} | ||
} |
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.
please also test the case where the user isn't set on the session
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.
please also test the case where the user isn't set on the session
888b433
to
1a87de3
Compare
username = user.name(); | ||
if (user == null) { | ||
throw new UnsupportedFeatureException( | ||
String.format(Locale.ENGLISH, "%s function is only supported in enterprise version", name) |
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.
hm but it also can be null if the user management is disabled...
Codecov Report
@@ Coverage Diff @@
## master #5807 +/- ##
========================================
Coverage ? 83.1%
Complexity ? 12201
========================================
Files ? 1428
Lines ? 46642
Branches ? 5754
========================================
Hits ? 38764
Misses ? 5209
Partials ? 2669
Continue to review full report at Codecov.
|
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.
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?
@mfussenegger Discussed with @dobe to throw UnsupportedFeatureException as it's an enterprise feature (to be consistent with |
f8de716
to
3ff4b32
Compare
8da56c9
to
3c77f49
Compare
3c77f49
to
09f6240
Compare
No description provided.