Skip to content

Commit

Permalink
HIVE-2994 Pass a environment context to metastore thrift APIs
Browse files Browse the repository at this point in the history
(Delia David via namit)



git-svn-id: https://svn.apache.org/repos/asf/hive/trunk@1334053 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Namit Jain committed May 4, 2012
1 parent a5b597e commit ad39f1c
Show file tree
Hide file tree
Showing 23 changed files with 16,673 additions and 7,132 deletions.
Expand Up @@ -20,6 +20,7 @@

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.apache.commons.lang.StringEscapeUtils;
Expand Down Expand Up @@ -108,13 +109,49 @@ private void insertToDB(Set<ReadEntity> inputs,
String sql = "insert into snc1_command_log " +
" set command = ?, inputs = ?, outputs = ?, command_type = ?";

String ipAddress = HMSHandler.getIpAddress();
if (ipAddress != null) {
if (ipAddress.startsWith("/")) {
ipAddress = ipAddress.replaceFirst("/", "");
String user_info = null;
String query_src = null;

// The Metastore Thrift API allows clients to set environment properties for
// selected operations (alter / create table and partition,
// i.e. create_table_with_environment_context).
// If present, the environment context is passed to all listeners.
// The following lines check if user information and query source were passed
// through the environment context.

String ENV_CONTEXT_USER_INFO = "user_info";
String ENV_CONTEXT_QUERY_SRC = "query_src";

if (event.getEnvironmentContext() != null &&
event.getEnvironmentContext().getProperties() != null &&
!event.getEnvironmentContext().getProperties().isEmpty()) {
Map<String, String> envProperties =
event.getEnvironmentContext().getProperties();
if (envProperties.get(ENV_CONTEXT_USER_INFO) != null) {
user_info = envProperties.get(ENV_CONTEXT_USER_INFO);
}
if (envProperties.get(ENV_CONTEXT_QUERY_SRC) != null) {
query_src = envProperties.get(ENV_CONTEXT_QUERY_SRC);
}
}

if (user_info == null) {
String ipAddress = HMSHandler.getIpAddress();
if (ipAddress != null) {
if (ipAddress.startsWith("/")) {
ipAddress = ipAddress.replaceFirst("/", "");
}
user_info = ipAddress;
}
}

if (user_info != null) {
sql += ", user_info = ?";
sqlParams.add(ipAddress);
sqlParams.add(user_info);
}
if (query_src != null) {
sql += ", query_src = ?";
sqlParams.add(StringEscapeUtils.escapeJava(query_src));
}

HookUtils.runInsert(conf, urlFactory, sql, sqlParams, HookUtils
Expand Down
26 changes: 25 additions & 1 deletion metastore/if/hive_metastore.thrift
Expand Up @@ -193,6 +193,14 @@ struct Schema {
2: map<string, string> properties
}

// Key-value store to be used with selected
// Metastore APIs (create, alter methods).
// The client can pass environment properties / configs that can be
// accessed in hooks.
struct EnvironmentContext {
1: map<string, string> properties
}

exception MetaException {
1: string message
}
Expand Down Expand Up @@ -272,6 +280,11 @@ service ThriftHiveMetastore extends fb303.FacebookService
// sd.serdeInfo.serializationLib (SerDe class name eg org.apache.hadoop.hive.serde.simple_meta.MetadataTypedColumnsetSerDe
// * See notes on DDL_TIME
void create_table(1:Table tbl) throws(1:AlreadyExistsException o1, 2:InvalidObjectException o2, 3:MetaException o3, 4:NoSuchObjectException o4)
void create_table_with_environment_context(1:Table tbl,
2:EnvironmentContext environment_context)
throws (1:AlreadyExistsException o1,
2:InvalidObjectException o2, 3:MetaException o3,
4:NoSuchObjectException o4)
// drops the table and all the partitions associated with it if the table has partitions
// delete data (including partitions) if deleteData is set to true
void drop_table(1:string dbname, 2:string name, 3:bool deleteData)
Expand Down Expand Up @@ -325,11 +338,17 @@ service ThriftHiveMetastore extends fb303.FacebookService
// * See notes on DDL_TIME
void alter_table(1:string dbname, 2:string tbl_name, 3:Table new_tbl)
throws (1:InvalidOperationException o1, 2:MetaException o2)

void alter_table_with_environment_context(1:string dbname, 2:string tbl_name,
3:Table new_tbl, 4:EnvironmentContext environment_context)
throws (1:InvalidOperationException o1, 2:MetaException o2)
// the following applies to only tables that have partitions
// * See notes on DDL_TIME
Partition add_partition(1:Partition new_part)
throws(1:InvalidObjectException o1, 2:AlreadyExistsException o2, 3:MetaException o3)
Partition add_partition_with_environment_context(1:Partition new_part,
2:EnvironmentContext environment_context)
throws (1:InvalidObjectException o1, 2:AlreadyExistsException o2,
3:MetaException o3)
i32 add_partitions(1:list<Partition> new_parts)
throws(1:InvalidObjectException o1, 2:AlreadyExistsException o2, 3:MetaException o3)
Partition append_partition(1:string db_name, 2:string tbl_name, 3:list<string> part_vals)
Expand Down Expand Up @@ -390,6 +409,11 @@ service ThriftHiveMetastore extends fb303.FacebookService
void alter_partition(1:string db_name, 2:string tbl_name, 3:Partition new_part)
throws (1:InvalidOperationException o1, 2:MetaException o2)

void alter_partition_with_environment_context(1:string db_name,
2:string tbl_name, 3:Partition new_part,
4:EnvironmentContext environment_context)
throws (1:InvalidOperationException o1, 2:MetaException o2)

// rename the old partition to the new partition object by changing old part values to the part values
// in the new_part. old partition is identified from part_vals.
// partition keys in new_part should be the same as those in old partition.
Expand Down

0 comments on commit ad39f1c

Please sign in to comment.