You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by GitBox <gi...@apache.org> on 2019/02/27 21:20:40 UTC
[GitHub] julianhyde commented on a change in pull request #1031:
CALCITE-2742: Update RexImpTable to use DataContext to retrieve USER and
SYSTEM_USER
julianhyde commented on a change in pull request #1031: CALCITE-2742: Update RexImpTable to use DataContext to retrieve USER and SYSTEM_USER
URL: https://github.com/apache/calcite/pull/1031#discussion_r260949061
##########
File path: core/src/test/java/org/apache/calcite/rex/RexExecutorTest.java
##########
@@ -175,6 +176,58 @@ private void checkConstant(final Object operand,
});
}
+ @Test public void testUserFromContext() throws Exception {
+ testContextLiteral(SqlStdOperatorTable.USER,
+ DataContext.Variable.USER, "happyCalciteUser");
+ }
+
+ @Test public void testSystemUserFromContext() throws Exception {
+ testContextLiteral(SqlStdOperatorTable.SYSTEM_USER,
+ DataContext.Variable.SYSTEM_USER, "");
+ }
+
+ @Test public void testTimestampFromContext() throws Exception {
+ // current timestamp currently rounds to the nearest second (?)
+ long val = System.currentTimeMillis() / 1000 * 1000;
+ testContextLiteral(SqlStdOperatorTable.CURRENT_TIMESTAMP,
+ DataContext.Variable.CURRENT_TIMESTAMP, val);
+ }
+
+ /**
+ * Ensure that for a given context operator, the correct value is retrieved from the DataContext.
+ * @param operator The Operator to check
+ * @param variable The DataContext variable this operator should be bound to.
+ * @param value The expected value to retrieve.
+ */
+ private void testContextLiteral(
+ final SqlOperator operator,
+ final DataContext.Variable variable,
+ final Object value) {
+ Frameworks.withPrepare(new Frameworks.PrepareAction<Void>() {
+ public Void apply(final RelOptCluster cluster,
+ final RelOptSchema relOptSchema,
+ final SchemaPlus rootSchema,
+ final CalciteServerStatement statement) {
+ final RexBuilder rexBuilder = cluster.getRexBuilder();
+ final RexExecutorImpl executor = new RexExecutorImpl(
+ new SingleValueDataContext(variable.camelName, value));
+ try {
+ checkConstant(value, new Function<RexBuilder, RexNode>() {
+ public RexNode apply(RexBuilder builder) {
+ List<RexNode> output = new ArrayList<>();
+ executor.reduce(rexBuilder,
+ ImmutableList.of(rexBuilder.makeCall(operator)), output);
+ return output.get(0);
+ }
+ });
+ } catch (Exception e) {
+ throw new RuntimeException(e);
Review comment:
@vlsi Is it possible to add a forbidden-apis check to flag these violations?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services