drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ve...@apache.org
Subject [4/5] drill git commit: DRILL-2902: Add support for context functions: user (synonyms session_user and system_user) and current_schema
Date Wed, 06 May 2015 00:27:38 GMT
DRILL-2902: Add support for context functions: user (synonyms session_user and system_user) and current_schema


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/703314ba
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/703314ba
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/703314ba

Branch: refs/heads/master
Commit: 703314baf3cf1ddd4756b838449421271703ca37
Parents: ac823fe
Author: vkorukanti <venki.korukanti@gmail.com>
Authored: Tue Apr 28 17:57:00 2015 -0700
Committer: vkorukanti <venki.korukanti@gmail.com>
Committed: Tue May 5 11:03:58 2015 -0700

----------------------------------------------------------------------
 .../apache/drill/exec/client/DrillClient.java   |    4 +-
 .../exec/expr/fn/impl/ContextFunctions.java     |   80 +
 .../exec/expr/fn/impl/DateTypeFunctions.java    |   34 +-
 .../drill/exec/ops/ContextInformation.java      |   66 +
 .../apache/drill/exec/ops/FragmentContext.java  |    9 +-
 .../org/apache/drill/exec/ops/QueryContext.java |   18 +-
 .../drill/exec/ops/QueryDateTimeInfo.java       |   36 -
 .../org/apache/drill/exec/ops/UdfUtilities.java |   16 +-
 .../planner/fragment/SimpleParallelizer.java    |   16 +-
 .../apache/drill/exec/rpc/user/UserSession.java |    4 +
 .../org/apache/drill/exec/util/Utilities.java   |   19 +
 .../apache/drill/exec/work/foreman/Foreman.java |    2 +-
 .../exec/fn/impl/TestContextFunctions.java      |   93 +
 .../fn/interp/ExpressionInterpreterTest.java    |    8 +-
 .../exec/physical/impl/TestLocalExchange.java   |   13 +-
 .../partitionsender/TestPartitionSender.java    |   11 +-
 .../drill/exec/pop/TestFragmentChecker.java     |   12 +-
 .../security/TestCustomUserAuthenticator.java   |    2 +-
 .../exec/testing/TestExceptionInjection.java    |    3 +
 .../drill/exec/testing/TestPauseInjection.java  |    2 +
 .../org/apache/drill/exec/proto/BitControl.java | 1655 +++++++++++++-----
 .../drill/exec/proto/SchemaBitControl.java      |  162 +-
 .../drill/exec/proto/beans/PlanFragment.java    |   76 +-
 .../proto/beans/QueryContextInformation.java    |  207 +++
 protocol/src/main/protobuf/BitControl.proto     |   15 +-
 25 files changed, 1930 insertions(+), 633 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/703314ba/exec/java-exec/src/main/java/org/apache/drill/exec/client/DrillClient.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/client/DrillClient.java b/exec/java-exec/src/main/java/org/apache/drill/exec/client/DrillClient.java
index 4576eb4..3fda9c1 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/client/DrillClient.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/client/DrillClient.java
@@ -20,6 +20,8 @@ package org.apache.drill.exec.client;
 import static com.google.common.base.Preconditions.checkState;
 import static org.apache.drill.exec.proto.UserProtos.QueryResultsMode.STREAM_FULL;
 import static org.apache.drill.exec.proto.UserProtos.RunQuery.newBuilder;
+
+import com.google.common.base.Strings;
 import io.netty.buffer.DrillBuf;
 
 import java.io.Closeable;
@@ -301,7 +303,7 @@ public class DrillClient implements Closeable, ConnectionThrottle {
 
     if (props != null) {
       for (Property property: props.getPropertiesList()) {
-        if (property.getKey().equalsIgnoreCase("user")) {
+        if (property.getKey().equalsIgnoreCase("user") && !Strings.isNullOrEmpty(property.getValue())) {
           userName = property.getValue();
           break;
         }

http://git-wip-us.apache.org/repos/asf/drill/blob/703314ba/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ContextFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ContextFunctions.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ContextFunctions.java
new file mode 100644
index 0000000..9d4696d
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ContextFunctions.java
@@ -0,0 +1,80 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.expr.fn.impl;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+import org.apache.drill.exec.ops.ContextInformation;
+
+import javax.inject.Inject;
+
+@SuppressWarnings("unused")
+public class ContextFunctions {
+
+  /**
+   * Implement "user", "session_user" or "system_user" function. Returns the username of the user connected to Drillbit.
+   */
+  @FunctionTemplate(names = {"user", "session_user", "system_user"}, scope = FunctionTemplate.FunctionScope.SIMPLE)
+  public static class User implements DrillSimpleFunc {
+    @Output VarCharHolder out;
+    @Inject ContextInformation contextInfo;
+    @Inject DrillBuf buffer;
+    @Workspace int queryUserBytesLength;
+
+    public void setup() {
+      final byte[] queryUserNameBytes = contextInfo.getQueryUser().getBytes();
+      buffer = buffer.reallocIfNeeded(queryUserNameBytes.length);
+      queryUserBytesLength = queryUserNameBytes.length;
+      buffer.setBytes(0, queryUserNameBytes);
+    }
+
+    public void eval() {
+      out.start = 0;
+      out.end = queryUserBytesLength;
+      out.buffer = buffer;
+    }
+  }
+
+  /**
+   * Implement "current_schema" function. Returns the default schema in current session.
+   */
+  @FunctionTemplate(name = "current_schema", scope = FunctionTemplate.FunctionScope.SIMPLE)
+  public static class CurrentSchema implements DrillSimpleFunc {
+    @Output VarCharHolder out;
+    @Inject ContextInformation contextInfo;
+    @Inject DrillBuf buffer;
+    @Workspace int currentSchemaBytesLength;
+
+    public void setup() {
+      final byte[] currentSchemaBytes = contextInfo.getCurrentDefaultSchema().getBytes();
+      buffer = buffer.reallocIfNeeded(currentSchemaBytes.length);
+      currentSchemaBytesLength= currentSchemaBytes.length;
+      buffer.setBytes(0, currentSchemaBytes);
+    }
+
+    public void eval() {
+      out.start = 0;
+      out.end = currentSchemaBytesLength;
+      out.buffer = buffer;
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/703314ba/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/DateTypeFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/DateTypeFunctions.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/DateTypeFunctions.java
index 9c932d6..41ce328 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/DateTypeFunctions.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/DateTypeFunctions.java
@@ -36,7 +36,7 @@ import org.apache.drill.exec.expr.holders.IntervalYearHolder;
 import org.apache.drill.exec.expr.holders.TimeHolder;
 import org.apache.drill.exec.expr.holders.TimeStampHolder;
 import org.apache.drill.exec.expr.holders.VarCharHolder;
-import org.apache.drill.exec.ops.QueryDateTimeInfo;
+import org.apache.drill.exec.ops.ContextInformation;
 
 public class DateTypeFunctions {
 
@@ -181,13 +181,13 @@ public class DateTypeFunctions {
     public static class CurrentDate implements DrillSimpleFunc {
         @Workspace long queryStartDate;
         @Output DateHolder out;
-        @Inject QueryDateTimeInfo dateTime;
+        @Inject ContextInformation contextInfo;
 
         public void setup() {
 
-            int timeZoneIndex = dateTime.getRootFragmentTimeZone();
+            int timeZoneIndex = contextInfo.getRootFragmentTimeZone();
             org.joda.time.DateTimeZone timeZone = org.joda.time.DateTimeZone.forID(org.apache.drill.exec.expr.fn.impl.DateUtility.getTimeZone(timeZoneIndex));
-            org.joda.time.DateTime now = new org.joda.time.DateTime(dateTime.getQueryStartTime(), timeZone);
+            org.joda.time.DateTime now = new org.joda.time.DateTime(contextInfo.getQueryStartTime(), timeZone);
             queryStartDate = (new org.joda.time.DateMidnight(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), timeZone)).
                 withZoneRetainFields(org.joda.time.DateTimeZone.UTC).getMillis();
         }
@@ -220,11 +220,11 @@ public class DateTypeFunctions {
     public static class LocalTimeStamp implements DrillSimpleFunc {
         @Workspace long queryStartDate;
         @Output TimeStampHolder out;
-        @Inject QueryDateTimeInfo dateTime;
+        @Inject ContextInformation contextInfo;
 
         public void setup() {
 
-            org.joda.time.DateTime now = (new org.joda.time.DateTime(dateTime.getQueryStartTime())).withZoneRetainFields(org.joda.time.DateTimeZone.UTC);
+            org.joda.time.DateTime now = (new org.joda.time.DateTime(contextInfo.getQueryStartTime())).withZoneRetainFields(org.joda.time.DateTimeZone.UTC);
             queryStartDate = now.getMillis();
         }
 
@@ -237,13 +237,13 @@ public class DateTypeFunctions {
     public static class CurrentTime implements DrillSimpleFunc {
         @Workspace int queryStartTime;
         @Output TimeHolder out;
-        @Inject QueryDateTimeInfo dateTime;
+        @Inject ContextInformation contextInfo;
 
         public void setup() {
 
-            int timeZoneIndex = dateTime.getRootFragmentTimeZone();
+            int timeZoneIndex = contextInfo.getRootFragmentTimeZone();
             org.joda.time.DateTimeZone timeZone = org.joda.time.DateTimeZone.forID(org.apache.drill.exec.expr.fn.impl.DateUtility.getTimeZone(timeZoneIndex));
-            org.joda.time.DateTime now = new org.joda.time.DateTime(dateTime.getQueryStartTime(), timeZone);
+            org.joda.time.DateTime now = new org.joda.time.DateTime(contextInfo.getQueryStartTime(), timeZone);
             queryStartTime= (int) ((now.getHourOfDay() * org.apache.drill.exec.expr.fn.impl.DateUtility.hoursToMillis) +
                                    (now.getMinuteOfHour() * org.apache.drill.exec.expr.fn.impl.DateUtility.minutesToMillis) +
                                    (now.getSecondOfMinute() * org.apache.drill.exec.expr.fn.impl.DateUtility.secondsToMillis) +
@@ -331,12 +331,12 @@ public class DateTypeFunctions {
         @Param TimeStampHolder right;
         @Workspace long queryStartDate;
         @Output IntervalHolder out;
-        @Inject QueryDateTimeInfo dateTime;
+        @Inject ContextInformation contextInfo;
 
         public void setup() {
-            int timeZoneIndex = dateTime.getRootFragmentTimeZone();
+            int timeZoneIndex = contextInfo.getRootFragmentTimeZone();
             org.joda.time.DateTimeZone timeZone = org.joda.time.DateTimeZone.forID(org.apache.drill.exec.expr.fn.impl.DateUtility.getTimeZone(timeZoneIndex));
-            org.joda.time.DateTime now = new org.joda.time.DateTime(dateTime.getQueryStartTime(), timeZone);
+            org.joda.time.DateTime now = new org.joda.time.DateTime(contextInfo.getQueryStartTime(), timeZone);
             queryStartDate = (new org.joda.time.DateMidnight(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), timeZone)).getMillis();
         }
 
@@ -374,12 +374,12 @@ public class DateTypeFunctions {
         @Param DateHolder right;
         @Workspace long queryStartDate;
         @Output IntervalHolder out;
-        @Inject QueryDateTimeInfo dateTime;
+        @Inject ContextInformation contextInfo;
 
         public void setup() {
-            int timeZoneIndex = dateTime.getRootFragmentTimeZone();
+            int timeZoneIndex = contextInfo.getRootFragmentTimeZone();
             org.joda.time.DateTimeZone timeZone = org.joda.time.DateTimeZone.forID(org.apache.drill.exec.expr.fn.impl.DateUtility.getTimeZone(timeZoneIndex));
-            org.joda.time.DateTime now = new org.joda.time.DateTime(dateTime.getQueryStartTime(), timeZone);
+            org.joda.time.DateTime now = new org.joda.time.DateTime(contextInfo.getQueryStartTime(), timeZone);
             queryStartDate = (new org.joda.time.DateMidnight(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), timeZone)).getMillis();
         }
 
@@ -411,11 +411,11 @@ public class DateTypeFunctions {
     public static class UnixTimeStamp implements DrillSimpleFunc {
       @Output BigIntHolder out;
       @Workspace long queryStartDate;
-      @Inject QueryDateTimeInfo dateTime;
+      @Inject ContextInformation contextInfo;
 
       @Override
       public void setup() {
-         queryStartDate = dateTime.getQueryStartTime();
+         queryStartDate = contextInfo.getQueryStartTime();
       }
 
       @Override

http://git-wip-us.apache.org/repos/asf/drill/blob/703314ba/exec/java-exec/src/main/java/org/apache/drill/exec/ops/ContextInformation.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/ops/ContextInformation.java b/exec/java-exec/src/main/java/org/apache/drill/exec/ops/ContextInformation.java
new file mode 100644
index 0000000..7054f36
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/ops/ContextInformation.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.drill.exec.ops;
+
+import org.apache.drill.exec.proto.BitControl.QueryContextInformation;
+import org.apache.drill.exec.proto.UserBitShared.UserCredentials;
+
+/**
+ * Provides query context information (such as query start time, query user, default schema etc.) for UDFs.
+ */
+public class ContextInformation {
+  private final String queryUser;
+  private final String currentDefaultSchema;
+  private final long queryStartTime;
+  private final int rootFragmentTimeZone;
+
+  public ContextInformation(final UserCredentials userCredentials, final QueryContextInformation queryContextInfo) {
+    this.queryUser = userCredentials.getUserName();
+    this.currentDefaultSchema = queryContextInfo.getDefaultSchemaName();
+    this.queryStartTime = queryContextInfo.getQueryStartTime();
+    this.rootFragmentTimeZone = queryContextInfo.getTimeZone();
+  }
+
+  /**
+   * @return userName of the user who issued the current query.
+   */
+  public String getQueryUser() {
+    return queryUser;
+  }
+
+  /**
+   * @return Get the current default schema in user session at the time of this particular query submission.
+   */
+  public String getCurrentDefaultSchema() {
+    return currentDefaultSchema;
+  }
+
+  /**
+   * @return Query start time in milliseconds
+   */
+  public long getQueryStartTime() {
+    return queryStartTime;
+  }
+
+  /**
+   * @return Time zone.
+   */
+  public int getRootFragmentTimeZone() {
+    return rootFragmentTimeZone;
+  }
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/703314ba/exec/java-exec/src/main/java/org/apache/drill/exec/ops/FragmentContext.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/ops/FragmentContext.java b/exec/java-exec/src/main/java/org/apache/drill/exec/ops/FragmentContext.java
index 09a7568..b108924 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/ops/FragmentContext.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/ops/FragmentContext.java
@@ -24,7 +24,6 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.calcite.schema.SchemaPlus;
-import org.apache.calcite.jdbc.SimpleCalciteSchema;
 
 import org.apache.drill.common.config.DrillConfig;
 import org.apache.drill.common.exceptions.ExecutionSetupException;
@@ -76,7 +75,7 @@ public class FragmentContext implements AutoCloseable, UdfUtilities {
   private final FunctionImplementationRegistry funcRegistry;
   private final BufferAllocator allocator;
   private final PlanFragment fragment;
-  private final QueryDateTimeInfo queryDateTimeInfo;
+  private final ContextInformation contextInformation;
   private IncomingBuffers buffers;
   private final OptionManager fragmentOptions;
   private final BufferManager bufferManager;
@@ -126,7 +125,7 @@ public class FragmentContext implements AutoCloseable, UdfUtilities {
     this.accountingUserConnection = new AccountingUserConnection(connection, sendingAccountor, statusHandler);
     this.fragment = fragment;
     this.funcRegistry = funcRegistry;
-    queryDateTimeInfo = new QueryDateTimeInfo(fragment.getQueryStartTime(), fragment.getTimeZone());
+    contextInformation = new ContextInformation(fragment.getCredentials(), fragment.getContext());
 
     logger.debug("Getting initial memory allocation of {}", fragment.getMemInitial());
     logger.debug("Fragment max allocation: {}", fragment.getMemMax());
@@ -234,8 +233,8 @@ public class FragmentContext implements AutoCloseable, UdfUtilities {
   }
 
   @Override
-  public QueryDateTimeInfo getQueryDateTimeInfo(){
-    return this.queryDateTimeInfo;
+  public ContextInformation getContextInformation() {
+    return contextInformation;
   }
 
   public DrillbitEndpoint getForemanEndpoint() {

http://git-wip-us.apache.org/repos/asf/drill/blob/703314ba/exec/java-exec/src/main/java/org/apache/drill/exec/ops/QueryContext.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/ops/QueryContext.java b/exec/java-exec/src/main/java/org/apache/drill/exec/ops/QueryContext.java
index 6414f56..9e2f210 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/ops/QueryContext.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/ops/QueryContext.java
@@ -33,6 +33,7 @@ import org.apache.drill.exec.memory.BufferAllocator;
 import org.apache.drill.exec.memory.OutOfMemoryException;
 import org.apache.drill.exec.planner.physical.PlannerSettings;
 import org.apache.drill.exec.planner.sql.DrillOperatorTable;
+import org.apache.drill.exec.proto.BitControl.QueryContextInformation;
 import org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint;
 import org.apache.drill.exec.rpc.user.UserSession;
 import org.apache.drill.exec.server.DrillbitContext;
@@ -44,6 +45,7 @@ import org.apache.drill.exec.store.SchemaConfig;
 import org.apache.drill.exec.store.StoragePluginRegistry;
 import org.apache.drill.exec.testing.ExecutionControls;
 import org.apache.drill.exec.util.ImpersonationUtil;
+import org.apache.drill.exec.util.Utilities;
 
 // TODO except for a couple of tests, this is only created by Foreman
 // TODO the many methods that just return drillbitContext.getXxx() should be replaced with getDrillbitContext()
@@ -64,7 +66,8 @@ public class QueryContext implements AutoCloseable, UdfUtilities {
 
   private final BufferAllocator allocator;
   private final BufferManager bufferManager;
-  private final QueryDateTimeInfo queryDateTimeInfo;
+  private final ContextInformation contextInformation;
+  private final QueryContextInformation queryContextInfo;
   private final ViewExpansionContext viewExpansionContext;
 
   /*
@@ -82,9 +85,8 @@ public class QueryContext implements AutoCloseable, UdfUtilities {
     plannerSettings.setNumEndPoints(drillbitContext.getBits().size());
     table = new DrillOperatorTable(getFunctionRegistry());
 
-    final long queryStartTime = System.currentTimeMillis();
-    final int timeZone = DateUtility.getIndex(System.getProperty("user.timezone"));
-    queryDateTimeInfo = new QueryDateTimeInfo(queryStartTime, timeZone);
+    queryContextInfo = Utilities.createQueryContextInfo(session.getDefaultSchemaName());
+    contextInformation = new ContextInformation(session.getCredentials(), queryContextInfo);
 
     try {
       allocator = drillbitContext.getAllocator().getChildAllocator(null, INITIAL_OFF_HEAP_ALLOCATION_IN_BYTES,
@@ -212,9 +214,13 @@ public class QueryContext implements AutoCloseable, UdfUtilities {
     return table;
   }
 
+  public QueryContextInformation getQueryContextInfo() {
+    return queryContextInfo;
+  }
+
   @Override
-  public QueryDateTimeInfo getQueryDateTimeInfo() {
-    return queryDateTimeInfo;
+  public ContextInformation getContextInformation() {
+    return contextInformation;
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/drill/blob/703314ba/exec/java-exec/src/main/java/org/apache/drill/exec/ops/QueryDateTimeInfo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/ops/QueryDateTimeInfo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/ops/QueryDateTimeInfo.java
deleted file mode 100644
index f3cc666..0000000
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/ops/QueryDateTimeInfo.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- ******************************************************************************/
-package org.apache.drill.exec.ops;
-
-public class QueryDateTimeInfo {
-  private final long queryStartTime;
-  private final int rootFragmentTimeZone;
-
-  public QueryDateTimeInfo(long queryStartTime, int rootFragmentTimeZone) {
-    this.queryStartTime = queryStartTime;
-    this.rootFragmentTimeZone = rootFragmentTimeZone;
-  }
-
-  public long getQueryStartTime() {
-    return this.queryStartTime;
-  }
-
-  public int getRootFragmentTimeZone() {
-    return this.rootFragmentTimeZone;
-  }
-}

http://git-wip-us.apache.org/repos/asf/drill/blob/703314ba/exec/java-exec/src/main/java/org/apache/drill/exec/ops/UdfUtilities.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/ops/UdfUtilities.java b/exec/java-exec/src/main/java/org/apache/drill/exec/ops/UdfUtilities.java
index 1cdece1..9c91331 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/ops/UdfUtilities.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/ops/UdfUtilities.java
@@ -34,18 +34,22 @@ public interface UdfUtilities {
   public static final ImmutableMap<Class, String> INJECTABLE_GETTER_METHODS =
       new ImmutableMap.Builder<Class, String>()
           .put(DrillBuf.class, "getManagedBuffer")
-          .put(QueryDateTimeInfo.class, "getQueryDateTimeInfo")
           .put(PartitionExplorer.class, "getPartitionExplorer")
+          .put(ContextInformation.class, "getContextInformation")
           .build();
 
+
   /**
-   * Get the query start time and timezone recorded by the head node during
-   * planning. This allows for SQL functions like now() to return a stable
-   * result within the context of a distributed query.
+   * Get the context information such as:
+   *  - query start time
+   *  - root fragment timezone
+   *  - query userName
+   *  - system userName
+   *  - default schema name in current session at the time of query.
    *
-   * @return - object wrapping the raw time and timezone values
+   * @return - ContextInformation
    */
-  QueryDateTimeInfo getQueryDateTimeInfo();
+  ContextInformation getContextInformation();
 
   /**
    * For UDFs to allocate general purpose intermediate buffers we provide the

http://git-wip-us.apache.org/repos/asf/drill/blob/703314ba/exec/java-exec/src/main/java/org/apache/drill/exec/planner/fragment/SimpleParallelizer.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/fragment/SimpleParallelizer.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/fragment/SimpleParallelizer.java
index 66ba229..d36ad42 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/fragment/SimpleParallelizer.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/fragment/SimpleParallelizer.java
@@ -34,7 +34,6 @@ import org.apache.drill.common.exceptions.ExecutionSetupException;
 import org.apache.drill.common.util.DrillStringUtils;
 import org.apache.drill.exec.ExecConstants;
 import org.apache.drill.exec.ops.QueryContext;
-import org.apache.drill.exec.ops.QueryDateTimeInfo;
 import org.apache.drill.exec.physical.EndpointAffinity;
 import org.apache.drill.exec.physical.PhysicalOperatorSetupException;
 import org.apache.drill.exec.physical.base.Exchange.ParallelizationDependency;
@@ -44,6 +43,7 @@ import org.apache.drill.exec.planner.PhysicalPlanReader;
 import org.apache.drill.exec.planner.fragment.Fragment.ExchangeFragmentPair;
 import org.apache.drill.exec.planner.fragment.Materializer.IndexedFragmentNode;
 import org.apache.drill.exec.proto.BitControl.PlanFragment;
+import org.apache.drill.exec.proto.BitControl.QueryContextInformation;
 import org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint;
 import org.apache.drill.exec.proto.ExecProtos.FragmentHandle;
 import org.apache.drill.exec.proto.UserBitShared.QueryId;
@@ -107,12 +107,13 @@ public class SimpleParallelizer {
    * @param reader          Tool used to read JSON plans
    * @param rootFragment    The root node of the PhysicalPlan that we will be parallelizing.
    * @param session         UserSession of user who launched this query.
+   * @param queryContextInfo Info related to the context when query has started.
    * @return The list of generated PlanFragment protobuf objects to be assigned out to the individual nodes.
    * @throws ExecutionSetupException
    */
   public QueryWorkUnit getFragments(OptionList options, DrillbitEndpoint foremanNode, QueryId queryId,
       Collection<DrillbitEndpoint> activeEndpoints, PhysicalPlanReader reader, Fragment rootFragment,
-      UserSession session, QueryDateTimeInfo queryDateTimeInfo) throws ExecutionSetupException {
+      UserSession session, QueryContextInformation queryContextInfo) throws ExecutionSetupException {
 
     final PlanningSet planningSet = new PlanningSet();
 
@@ -125,7 +126,8 @@ public class SimpleParallelizer {
       parallelizeFragment(wrapper, planningSet, activeEndpoints);
     }
 
-    return generateWorkUnit(options, foremanNode, queryId, reader, rootFragment, planningSet, session, queryDateTimeInfo);
+    return generateWorkUnit(
+        options, foremanNode, queryId, reader, rootFragment, planningSet, session, queryContextInfo);
   }
 
   // For every fragment, create a Wrapper in PlanningSet.
@@ -320,15 +322,12 @@ public class SimpleParallelizer {
 
   private QueryWorkUnit generateWorkUnit(OptionList options, DrillbitEndpoint foremanNode, QueryId queryId,
       PhysicalPlanReader reader, Fragment rootNode, PlanningSet planningSet,
-      UserSession session, QueryDateTimeInfo queryDateTimeInfo) throws ExecutionSetupException {
+      UserSession session, QueryContextInformation queryContextInfo) throws ExecutionSetupException {
     List<PlanFragment> fragments = Lists.newArrayList();
 
     PlanFragment rootFragment = null;
     FragmentRoot rootOperator = null;
 
-    long queryStartTime = queryDateTimeInfo.getQueryStartTime();
-    int timeZone = queryDateTimeInfo.getRootFragmentTimeZone();
-
     // now we generate all the individual plan fragments and associated assignments. Note, we need all endpoints
     // assigned before we can materialize, so we start a new loop here rather than utilizing the previous one.
     for (Wrapper wrapper : planningSet) {
@@ -374,8 +373,7 @@ public class SimpleParallelizer {
             .setHandle(handle) //
             .setAssignment(wrapper.getAssignedEndpoint(minorFragmentId)) //
             .setLeafFragment(isLeafFragment) //
-            .setQueryStartTime(queryStartTime)
-            .setTimeZone(timeZone)//
+            .setContext(queryContextInfo)
             .setMemInitial(wrapper.getInitialAllocation())//
             .setMemMax(wrapper.getMaxAllocation())
             .setOptionsJson(optionsData)

http://git-wip-us.apache.org/repos/asf/drill/blob/703314ba/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/UserSession.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/UserSession.java b/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/UserSession.java
index 527bac0..9f1a695 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/UserSession.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/UserSession.java
@@ -118,6 +118,10 @@ public class UserSession {
     return credentials;
   }
 
+  public String getDefaultSchemaName() {
+    return getProp(SCHEMA);
+  }
+
   public void incrementQueryCount(final QueryCountIncrementer incrementer) {
     assert incrementer != null;
     queryCount.incrementAndGet();

http://git-wip-us.apache.org/repos/asf/drill/blob/703314ba/exec/java-exec/src/main/java/org/apache/drill/exec/util/Utilities.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/util/Utilities.java b/exec/java-exec/src/main/java/org/apache/drill/exec/util/Utilities.java
index 8efb9e7..b0496bb 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/util/Utilities.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/util/Utilities.java
@@ -17,7 +17,9 @@
  */
 package org.apache.drill.exec.util;
 
+import org.apache.drill.exec.expr.fn.impl.DateUtility;
 import org.apache.drill.exec.ops.FragmentContext;
+import org.apache.drill.exec.proto.BitControl.QueryContextInformation;
 import org.apache.drill.exec.proto.ExecProtos;
 import org.apache.drill.exec.proto.helper.QueryIdHelper;
 
@@ -38,4 +40,21 @@ public class Utilities {
 
     return fileName;
   }
+
+  /**
+   * Create QueryContextInformation with given <i>defaultSchemaName</i>. Rest of the members of the
+   * QueryContextInformation is derived from the current state of the process.
+   *
+   * @param defaultSchemaName
+   * @return
+   */
+  public static QueryContextInformation createQueryContextInfo(final String defaultSchemaName) {
+    final long queryStartTime = System.currentTimeMillis();
+    final int timeZone = DateUtility.getIndex(System.getProperty("user.timezone"));
+    return QueryContextInformation.newBuilder()
+        .setDefaultSchemaName(defaultSchemaName)
+        .setQueryStartTime(queryStartTime)
+        .setTimeZone(timeZone)
+        .build();
+  }
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/703314ba/exec/java-exec/src/main/java/org/apache/drill/exec/work/foreman/Foreman.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/work/foreman/Foreman.java b/exec/java-exec/src/main/java/org/apache/drill/exec/work/foreman/Foreman.java
index 4249cbe..d678cc5 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/work/foreman/Foreman.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/work/foreman/Foreman.java
@@ -443,7 +443,7 @@ public class Foreman implements Runnable {
     final QueryWorkUnit queryWorkUnit = parallelizer.getFragments(
         queryContext.getOptions().getOptionList(), queryContext.getCurrentEndpoint(),
         queryId, queryContext.getActiveEndpoints(), drillbitContext.getPlanReader(), rootFragment,
-        initiatingClient.getSession(), queryContext.getQueryDateTimeInfo());
+        initiatingClient.getSession(), queryContext.getQueryContextInfo());
 
     if (logger.isTraceEnabled()) {
       final StringBuilder sb = new StringBuilder();

http://git-wip-us.apache.org/repos/asf/drill/blob/703314ba/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestContextFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestContextFunctions.java b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestContextFunctions.java
new file mode 100644
index 0000000..a3c473f
--- /dev/null
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestContextFunctions.java
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.fn.impl;
+
+import org.apache.drill.BaseTestQuery;
+import org.junit.Test;
+
+public class TestContextFunctions extends BaseTestQuery {
+
+  @Test
+  public void userUDFForAnonymousConnection() throws Exception {
+    updateClient("");
+    testBuilder()
+        .sqlQuery("select user, session_user, system_user from cp.`employee.json` limit 1")
+        .unOrdered()
+        .baselineColumns("user", "session_user", "system_user")
+        .baselineValues("anonymous", "anonymous", "anonymous")
+        .go();
+  }
+
+  @Test
+  public void userUDFForNamedConnection() throws Exception {
+    final String testUserName = "testUser1";
+    updateClient(testUserName);
+    testBuilder()
+        .sqlQuery("select user, session_user, system_user from cp.`employee.json` limit 1")
+        .unOrdered()
+        .baselineColumns("user", "session_user", "system_user")
+        .baselineValues(testUserName, testUserName, testUserName)
+        .go();
+  }
+
+  @Test
+  public void userUDFInFilterCondition() throws Exception {
+    final String testUserName = "testUser2";
+    updateClient(testUserName);
+    final String query = String.format(
+        "select employee_id from cp.`employee.json` where '%s' = user order by employee_id limit 1", testUserName);
+    testBuilder()
+        .sqlQuery(query)
+        .unOrdered()
+        .baselineColumns("employee_id")
+        .baselineValues(1L)
+        .go();
+  }
+
+  @Test
+  public void currentSchemaUDFWhenDefaultSchemaNotSet() throws Exception {
+    testBuilder()
+        .sqlQuery("select current_schema from cp.`employee.json` limit 1")
+        .unOrdered()
+        .baselineColumns("current_schema")
+        .baselineValues("")
+        .go();
+  }
+
+  @Test
+  public void currentSchemaUDFWithSingleLevelDefaultSchema() throws Exception {
+    testBuilder()
+        .optionSettingQueriesForTestQuery("USE dfs_test")
+        .sqlQuery("select current_schema from cp.`employee.json` limit 1")
+        .unOrdered()
+        .baselineColumns("current_schema")
+        .baselineValues("dfs_test")
+        .go();
+  }
+
+  @Test
+  public void currentSchemaUDFWithMultiLevelDefaultSchema() throws Exception {
+    testBuilder()
+        .optionSettingQueriesForTestQuery("USE dfs_test.tmp")
+        .sqlQuery("select current_schema from cp.`employee.json` limit 1")
+        .unOrdered()
+        .baselineColumns("current_schema")
+        .baselineValues("dfs_test.tmp")
+        .go();
+  }
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/703314ba/exec/java-exec/src/test/java/org/apache/drill/exec/fn/interp/ExpressionInterpreterTest.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/interp/ExpressionInterpreterTest.java b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/interp/ExpressionInterpreterTest.java
index 04e1980..2a83a53 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/interp/ExpressionInterpreterTest.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/interp/ExpressionInterpreterTest.java
@@ -39,10 +39,10 @@ import org.apache.drill.exec.expr.TypeHelper;
 import org.apache.drill.exec.expr.fn.interpreter.InterpreterEvaluator;
 import org.apache.drill.exec.expr.holders.TimeStampHolder;
 import org.apache.drill.exec.ops.FragmentContext;
-import org.apache.drill.exec.ops.QueryDateTimeInfo;
 import org.apache.drill.exec.physical.impl.ScanBatch;
 import org.apache.drill.exec.pop.PopUnitTestBase;
 import org.apache.drill.exec.proto.BitControl;
+import org.apache.drill.exec.proto.BitControl.QueryContextInformation;
 import org.apache.drill.exec.record.MaterializedField;
 import org.apache.drill.exec.record.RecordBatch;
 import org.apache.drill.exec.server.Drillbit;
@@ -127,10 +127,10 @@ public class ExpressionInterpreterTest  extends PopUnitTestBase {
     TypeProtos.MajorType[] colTypes = {Types.optional(TypeProtos.MinorType.INT)};
     String expressionStr = "now()";
     BitControl.PlanFragment planFragment = BitControl.PlanFragment.getDefaultInstance();
-    QueryDateTimeInfo dateTime = new QueryDateTimeInfo(planFragment.getQueryStartTime(), planFragment.getTimeZone());
-    int                        timeZoneIndex = dateTime.getRootFragmentTimeZone();
+    QueryContextInformation queryContextInfo = planFragment.getContext();
+    int                        timeZoneIndex = queryContextInfo.getTimeZone();
     org.joda.time.DateTimeZone timeZone = org.joda.time.DateTimeZone.forID(org.apache.drill.exec.expr.fn.impl.DateUtility.getTimeZone(timeZoneIndex));
-    org.joda.time.DateTime     now = new org.joda.time.DateTime(dateTime.getQueryStartTime(), timeZone);
+    org.joda.time.DateTime     now = new org.joda.time.DateTime(queryContextInfo.getQueryStartTime(), timeZone);
 
     long queryStartDate = now.getMillis();
 

http://git-wip-us.apache.org/repos/asf/drill/blob/703314ba/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestLocalExchange.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestLocalExchange.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestLocalExchange.java
index 9758eb0..09f8fcb 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestLocalExchange.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestLocalExchange.java
@@ -24,8 +24,6 @@ import com.google.common.collect.Lists;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.drill.PlanTestBase;
 import org.apache.drill.TestBuilder;
-import org.apache.drill.exec.expr.fn.impl.DateUtility;
-import org.apache.drill.exec.ops.QueryDateTimeInfo;
 import org.apache.drill.exec.physical.base.Exchange;
 import org.apache.drill.exec.physical.config.UnorderedDeMuxExchange;
 import org.apache.drill.exec.physical.config.HashToRandomExchange;
@@ -34,16 +32,16 @@ import org.apache.drill.exec.planner.fragment.Fragment;
 import org.apache.drill.exec.planner.fragment.Fragment.ExchangeFragmentPair;
 import org.apache.drill.exec.planner.fragment.PlanningSet;
 import org.apache.drill.exec.planner.fragment.SimpleParallelizer;
-import org.apache.drill.exec.planner.physical.HashPrelUtil;
-import org.apache.drill.exec.planner.physical.PrelUtil;
 import org.apache.drill.exec.pop.PopUnitTestBase;
 import org.apache.drill.exec.proto.BitControl.PlanFragment;
+import org.apache.drill.exec.proto.BitControl.QueryContextInformation;
 import org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint;
 import org.apache.drill.exec.proto.UserBitShared;
 import org.apache.drill.exec.proto.UserBitShared.QueryId;
 import org.apache.drill.exec.rpc.user.UserSession;
 import org.apache.drill.exec.server.DrillbitContext;
 import org.apache.drill.exec.server.options.OptionList;
+import org.apache.drill.exec.util.Utilities;
 import org.apache.drill.exec.work.QueryWorkUnit;
 import org.json.simple.JSONArray;
 import org.json.simple.JSONObject;
@@ -409,13 +407,10 @@ public class TestLocalExchange extends PlanTestBase {
 
     findFragmentsWithPartitionSender(rootFragment, planningSet, deMuxFragments, htrFragments);
 
-    long queryStartTime = System.currentTimeMillis();
-    int timeZone = DateUtility.getIndex(System.getProperty("user.timezone"));
-    QueryDateTimeInfo queryDateTimeInfo = new QueryDateTimeInfo(queryStartTime, timeZone);
-
+    final QueryContextInformation queryContextInfo = Utilities.createQueryContextInfo("dummySchemaName");
     QueryWorkUnit qwu = PARALLELIZER.getFragments(new OptionList(), drillbitContext.getEndpoint(),
         QueryId.getDefaultInstance(),
-        drillbitContext.getBits(), planReader, rootFragment, USER_SESSION, queryDateTimeInfo);
+        drillbitContext.getBits(), planReader, rootFragment, USER_SESSION, queryContextInfo);
 
     // Make sure the number of minor fragments with HashPartitioner within a major fragment is not more than the
     // number of Drillbits in cluster

http://git-wip-us.apache.org/repos/asf/drill/blob/703314ba/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/partitionsender/TestPartitionSender.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/partitionsender/TestPartitionSender.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/partitionsender/TestPartitionSender.java
index 6a6a7e0..320e722 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/partitionsender/TestPartitionSender.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/partitionsender/TestPartitionSender.java
@@ -30,11 +30,9 @@ import java.util.Random;
 
 import org.apache.drill.PlanTestBase;
 import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
-import org.apache.drill.exec.expr.fn.impl.DateUtility;
 import org.apache.drill.exec.memory.OutOfMemoryException;
 import org.apache.drill.exec.ops.FragmentContext;
 import org.apache.drill.exec.ops.OperatorStats;
-import org.apache.drill.exec.ops.QueryDateTimeInfo;
 import org.apache.drill.exec.physical.MinorFragmentEndpoint;
 import org.apache.drill.exec.physical.PhysicalPlan;
 import org.apache.drill.exec.physical.base.PhysicalOperator;
@@ -50,6 +48,7 @@ import org.apache.drill.exec.planner.fragment.PlanningSet;
 import org.apache.drill.exec.planner.fragment.SimpleParallelizer;
 import org.apache.drill.exec.pop.PopUnitTestBase;
 import org.apache.drill.exec.proto.BitControl.PlanFragment;
+import org.apache.drill.exec.proto.BitControl.QueryContextInformation;
 import org.apache.drill.exec.proto.UserBitShared;
 import org.apache.drill.exec.proto.UserBitShared.MetricValue;
 import org.apache.drill.exec.proto.UserBitShared.OperatorProfile;
@@ -64,6 +63,7 @@ import org.apache.drill.exec.server.DrillbitContext;
 import org.apache.drill.exec.server.options.OptionList;
 import org.apache.drill.exec.server.options.OptionValue;
 import org.apache.drill.exec.server.options.OptionValue.OptionType;
+import org.apache.drill.exec.util.Utilities;
 import org.apache.drill.exec.work.QueryWorkUnit;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
@@ -216,13 +216,10 @@ public class TestPartitionSender extends PlanTestBase {
       RecordBatch incoming, FunctionImplementationRegistry registry, PhysicalPlanReader planReader, PlanningSet planningSet, Fragment rootFragment,
       int expectedThreadsCount) throws Exception {
 
-    long queryStartTime = System.currentTimeMillis();
-    int timeZone = DateUtility.getIndex(System.getProperty("user.timezone"));
-    QueryDateTimeInfo queryDateTimeInfo = new QueryDateTimeInfo(queryStartTime, timeZone);
-
+    final QueryContextInformation queryContextInfo = Utilities.createQueryContextInfo("dummySchemaName");
     final QueryWorkUnit qwu = PARALLELIZER.getFragments(options, drillbitContext.getEndpoint(),
         QueryId.getDefaultInstance(),
-        drillbitContext.getBits(), planReader, rootFragment, USER_SESSION, queryDateTimeInfo);
+        drillbitContext.getBits(), planReader, rootFragment, USER_SESSION, queryContextInfo);
 
     final List<MinorFragmentEndpoint> mfEndPoints = PhysicalOperatorUtil.getIndexOrderedEndpoints(Lists.newArrayList(drillbitContext.getBits()));
 

http://git-wip-us.apache.org/repos/asf/drill/blob/703314ba/exec/java-exec/src/test/java/org/apache/drill/exec/pop/TestFragmentChecker.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/pop/TestFragmentChecker.java b/exec/java-exec/src/test/java/org/apache/drill/exec/pop/TestFragmentChecker.java
index 32e3bf9..0fbf0bd 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/pop/TestFragmentChecker.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/pop/TestFragmentChecker.java
@@ -19,18 +19,17 @@ package org.apache.drill.exec.pop;
 
 import java.util.List;
 
-import org.apache.drill.exec.expr.fn.impl.DateUtility;
-import org.apache.drill.exec.ops.QueryDateTimeInfo;
 import org.apache.drill.exec.planner.PhysicalPlanReader;
 import org.apache.drill.exec.planner.fragment.Fragment;
-import org.apache.drill.exec.planner.fragment.PlanningSet;
 import org.apache.drill.exec.planner.fragment.SimpleParallelizer;
 import org.apache.drill.exec.proto.BitControl.PlanFragment;
+import org.apache.drill.exec.proto.BitControl.QueryContextInformation;
 import org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint;
 import org.apache.drill.exec.proto.UserBitShared;
 import org.apache.drill.exec.proto.UserBitShared.QueryId;
 import org.apache.drill.exec.rpc.user.UserSession;
 import org.apache.drill.exec.server.options.OptionList;
+import org.apache.drill.exec.util.Utilities;
 import org.apache.drill.exec.work.QueryWorkUnit;
 import org.junit.Test;
 
@@ -62,13 +61,10 @@ public class TestFragmentChecker extends PopUnitTestBase{
       endpoints.add(b1);
     }
 
-    long queryStartTime = System.currentTimeMillis();
-    int timeZone = DateUtility.getIndex(System.getProperty("user.timezone"));
-    QueryDateTimeInfo queryDateTimeInfo = new QueryDateTimeInfo(queryStartTime, timeZone);
-
+    final QueryContextInformation queryContextInfo = Utilities.createQueryContextInfo("dummySchemaName");
     QueryWorkUnit qwu = par.getFragments(new OptionList(), localBit, QueryId.getDefaultInstance(), endpoints, ppr, fragmentRoot,
         UserSession.Builder.newBuilder().withCredentials(UserBitShared.UserCredentials.newBuilder().setUserName("foo").build()).build(),
-        queryDateTimeInfo);
+        queryContextInfo);
     System.out.println(String.format("=========ROOT FRAGMENT [%d:%d] =========", qwu.getRootFragment().getHandle().getMajorFragmentId(), qwu.getRootFragment().getHandle().getMinorFragmentId()));
 
     System.out.print(qwu.getRootFragment().getFragmentJson());

http://git-wip-us.apache.org/repos/asf/drill/blob/703314ba/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestCustomUserAuthenticator.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestCustomUserAuthenticator.java b/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestCustomUserAuthenticator.java
index 70d43b6..d9b4634 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestCustomUserAuthenticator.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestCustomUserAuthenticator.java
@@ -61,7 +61,7 @@ public class TestCustomUserAuthenticator extends BaseTestQuery {
     negativeAuthHelper(TEST_USER_1, "blah.. blah..");
     negativeAuthHelper(TEST_USER_2, "blah.. blah..");
     negativeAuthHelper(TEST_USER_2, "");
-    negativeAuthHelper("", "blah.. blah..");
+    negativeAuthHelper("invalidUserName", "blah.. blah..");
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/drill/blob/703314ba/exec/java-exec/src/test/java/org/apache/drill/exec/testing/TestExceptionInjection.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/testing/TestExceptionInjection.java b/exec/java-exec/src/test/java/org/apache/drill/exec/testing/TestExceptionInjection.java
index 604f375..e3558a1 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/testing/TestExceptionInjection.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/testing/TestExceptionInjection.java
@@ -24,6 +24,7 @@ import org.apache.drill.exec.exception.DrillbitStartupException;
 import org.apache.drill.exec.ops.QueryContext;
 import org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint;
 import org.apache.drill.exec.proto.UserBitShared;
+import org.apache.drill.exec.proto.UserProtos.UserProperties;
 import org.apache.drill.exec.rpc.user.UserSession;
 import org.apache.drill.exec.server.Drillbit;
 import org.apache.drill.exec.server.DrillbitContext;
@@ -40,6 +41,7 @@ public class TestExceptionInjection extends BaseTestQuery {
 
   private static final UserSession session = UserSession.Builder.newBuilder()
       .withCredentials(UserBitShared.UserCredentials.newBuilder().setUserName("foo").build())
+      .withUserProperties(UserProperties.getDefaultInstance())
       .withOptionManager(bits[0].getContext().getOptionManager())
       .build();
 
@@ -251,6 +253,7 @@ public class TestExceptionInjection extends BaseTestQuery {
 
     final UserSession session = UserSession.Builder.newBuilder()
         .withCredentials(UserBitShared.UserCredentials.newBuilder().setUserName("foo").build())
+        .withUserProperties(UserProperties.getDefaultInstance())
         .withOptionManager(drillbitContext1.getOptionManager())
         .build();
 

http://git-wip-us.apache.org/repos/asf/drill/blob/703314ba/exec/java-exec/src/test/java/org/apache/drill/exec/testing/TestPauseInjection.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/testing/TestPauseInjection.java b/exec/java-exec/src/test/java/org/apache/drill/exec/testing/TestPauseInjection.java
index 508b10c..5fa2b3f 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/testing/TestPauseInjection.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/testing/TestPauseInjection.java
@@ -20,6 +20,7 @@ package org.apache.drill.exec.testing;
 import org.apache.drill.BaseTestQuery;
 import org.apache.drill.exec.ops.QueryContext;
 import org.apache.drill.exec.proto.UserBitShared;
+import org.apache.drill.exec.proto.UserProtos.UserProperties;
 import org.apache.drill.exec.rpc.user.UserSession;
 import org.junit.Test;
 import org.slf4j.Logger;
@@ -31,6 +32,7 @@ public class TestPauseInjection extends BaseTestQuery {
 
   private static final UserSession session = UserSession.Builder.newBuilder()
       .withCredentials(UserBitShared.UserCredentials.newBuilder().setUserName("foo").build())
+      .withUserProperties(UserProperties.getDefaultInstance())
       .withOptionManager(bits[0].getContext().getOptionManager())
       .build();
 


Mime
View raw message