You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ga...@apache.org on 2015/03/17 16:50:32 UTC
svn commit: r1667338 [3/3] - in /hive/branches/hbase-metastore:
itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/
metastore/src/gen/protobuf/gen-java/org/apache/hadoop/hive/metastore/hbase/
metastore/src/java/org/apache/hadoop/hive...
Modified: hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseImport.java
URL: http://svn.apache.org/viewvc/hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseImport.java?rev=1667338&r1=1667337&r2=1667338&view=diff
==============================================================================
--- hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseImport.java (original)
+++ hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseImport.java Tue Mar 17 15:50:31 2015
@@ -27,6 +27,7 @@ import org.apache.hadoop.hive.conf.HiveC
import org.apache.hadoop.hive.metastore.ObjectStore;
import org.apache.hadoop.hive.metastore.RawStore;
import org.apache.hadoop.hive.metastore.api.Database;
+import org.apache.hadoop.hive.metastore.api.Function;
import org.apache.hadoop.hive.metastore.api.InvalidObjectException;
import org.apache.hadoop.hive.metastore.api.MetaException;
import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
@@ -76,11 +77,13 @@ public class HBaseImport {
@VisibleForTesting
void run() throws MetaException, InstantiationException, IllegalAccessException,
NoSuchObjectException, InvalidObjectException {
+ // Order here is crucial, as you can't add tables until you've added databases, etc.
init();
copyRoles();
copyDbs();
copyTables();
copyPartitions();
+ copyFunctions();
}
private void init() throws MetaException, IllegalAccessException, InstantiationException {
@@ -153,6 +156,18 @@ public class HBaseImport {
}
}
+ private void copyFunctions() throws MetaException, NoSuchObjectException, InvalidObjectException {
+ screen("Copying functions");
+ for (Database db : dbs) {
+ screen("Copying functions in database " + db.getName());
+ for (String funcName : rdbmsStore.getFunctions(db.getName(), "*")) {
+ Function func = rdbmsStore.getFunction(db.getName(), funcName);
+ screen("Copying function " + db.getName() + "." + funcName);
+ hbaseStore.createFunction(func);
+ }
+ }
+ }
+
private void screen(String msg) {
LOG.info(msg);
System.out.println(msg);
Modified: hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseReadWrite.java
URL: http://svn.apache.org/viewvc/hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseReadWrite.java?rev=1667338&r1=1667337&r2=1667338&view=diff
==============================================================================
--- hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseReadWrite.java (original)
+++ hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseReadWrite.java Tue Mar 17 15:50:31 2015
@@ -41,6 +41,7 @@ import org.apache.hadoop.hive.metastore.
import org.apache.hadoop.hive.metastore.api.ColumnStatisticsDesc;
import org.apache.hadoop.hive.metastore.api.ColumnStatisticsObj;
import org.apache.hadoop.hive.metastore.api.Database;
+import org.apache.hadoop.hive.metastore.api.Function;
import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
import org.apache.hadoop.hive.metastore.api.Partition;
import org.apache.hadoop.hive.metastore.api.PrincipalPrivilegeSet;
@@ -69,6 +70,7 @@ import java.util.Set;
class HBaseReadWrite {
@VisibleForTesting final static String DB_TABLE = "HBMS_DBS";
+ @VisibleForTesting final static String FUNC_TABLE = "HBMS_FUNCS";
@VisibleForTesting final static String GLOBAL_PRIVS_TABLE = "HBMS_GLOBAL_PRIVS";
@VisibleForTesting final static String PART_TABLE = "HBMS_PARTITIONS";
@VisibleForTesting final static String ROLE_TABLE = "HBMS_ROLES";
@@ -87,7 +89,7 @@ class HBaseReadWrite {
@VisibleForTesting final static String TEST_CONN = "test_connection";
private static HBaseConnection testConn;
- private final static String[] tableNames = { DB_TABLE, GLOBAL_PRIVS_TABLE, PART_TABLE,
+ private final static String[] tableNames = { DB_TABLE, FUNC_TABLE, GLOBAL_PRIVS_TABLE, PART_TABLE,
USER_TO_ROLE_TABLE, ROLE_TABLE, SD_TABLE, TABLE_TABLE };
static final private Log LOG = LogFactory.getLog(HBaseReadWrite.class.getName());
@@ -339,6 +341,73 @@ class HBaseReadWrite {
}
/**********************************************************************************************
+ * Function related methods
+ *********************************************************************************************/
+
+ /**
+ * Fetch a function object
+ * @param dbName name of the database the function is in
+ * @param functionName name of the function to fetch
+ * @return the function object, or null if there is no such function
+ * @throws IOException
+ */
+ Function getFunction(String dbName, String functionName) throws IOException {
+ byte[] key = HBaseUtils.buildKey(dbName, functionName);
+ byte[] serialized = read(FUNC_TABLE, key, CATALOG_CF, CATALOG_COL);
+ if (serialized == null) return null;
+ return HBaseUtils.deserializeFunction(dbName, functionName, serialized);
+ }
+
+ /**
+ * Get a list of functions.
+ * @param dbName Name of the database to search in.
+ * @param regex Regular expression to use in searching for function names. It is expected to
+ * be a Java regular expression. If it is null then all functions will be returned.
+ * @return list of functions matching the regular expression.
+ * @throws IOException
+ */
+ List<Function> scanFunctions(String dbName, String regex) throws IOException {
+ byte[] keyPrefix = null;
+ if (dbName != null) {
+ keyPrefix = HBaseUtils.buildKeyWithTrailingSeparator(dbName);
+ }
+ Filter filter = null;
+ if (regex != null) {
+ filter = new RowFilter(CompareFilter.CompareOp.EQUAL, new RegexStringComparator(regex));
+ }
+ Iterator<Result> iter =
+ scanWithFilter(FUNC_TABLE, keyPrefix, CATALOG_CF, CATALOG_COL, filter);
+ List<Function> functions = new ArrayList<Function>();
+ while (iter.hasNext()) {
+ Result result = iter.next();
+ functions.add(HBaseUtils.deserializeFunction(result.getRow(),
+ result.getValue(CATALOG_CF, CATALOG_COL)));
+ }
+ return functions;
+ }
+
+ /**
+ * Store a function object
+ * @param function function object to store
+ * @throws IOException
+ */
+ void putFunction(Function function) throws IOException {
+ byte[][] serialized = HBaseUtils.serializeFunction(function);
+ store(FUNC_TABLE, serialized[0], CATALOG_CF, CATALOG_COL, serialized[1]);
+ }
+
+ /**
+ * Drop a function
+ * @param dbName name of database the function is in
+ * @param functionName name of function to drop
+ * @throws IOException
+ */
+ void deleteFunction(String dbName, String functionName) throws IOException {
+ byte[] key = HBaseUtils.buildKey(dbName, functionName);
+ delete(FUNC_TABLE, key, null, null);
+ }
+
+ /**********************************************************************************************
* Global privilege related methods
*********************************************************************************************/
Modified: hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseSchemaTool.java
URL: http://svn.apache.org/viewvc/hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseSchemaTool.java?rev=1667338&r1=1667337&r2=1667338&view=diff
==============================================================================
--- hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseSchemaTool.java (original)
+++ hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseSchemaTool.java Tue Mar 17 15:50:31 2015
@@ -27,6 +27,7 @@ import org.apache.commons.lang.StringUti
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hive.metastore.api.ColumnStatistics;
import org.apache.hadoop.hive.metastore.api.Database;
+import org.apache.hadoop.hive.metastore.api.Function;
import org.apache.hadoop.hive.metastore.api.Partition;
import org.apache.hadoop.hive.metastore.api.Role;
import org.apache.hadoop.hive.metastore.api.Table;
@@ -46,7 +47,8 @@ import java.util.List;
*/
public class HBaseSchemaTool {
- private static String[] commands = {"db", "part", "parts", "role", "table", "install"};
+ private static String[] commands = {"db", "part", "parts", "role", "table", "function",
+ "install"};
public static void main(String[] args) throws Exception {
Options options = new Options();
@@ -64,6 +66,12 @@ public class HBaseSchemaTool {
.create('d'));
options.addOption(OptionBuilder
+ .withLongOpt("function")
+ .withDescription("Function name")
+ .hasArg()
+ .create('f'));
+
+ options.addOption(OptionBuilder
.withLongOpt("help")
.withDescription("You're looking at it")
.create('h'));
@@ -122,7 +130,7 @@ public class HBaseSchemaTool {
}
HBaseSchemaTool tool = new HBaseSchemaTool(cli.getOptionValue('d'), cli.getOptionValue('t'),
- parts, cli.getOptionValue('r'), cols, cli.hasOption('s'));
+ parts, cli.getOptionValue('f'), cli.getOptionValue('r'), cols, cli.hasOption('s'));
Method method = tool.getClass().getMethod(cmd);
method.invoke(tool);
@@ -131,17 +139,19 @@ public class HBaseSchemaTool {
private HBaseReadWrite hrw;
private String dbName;
+ private String funcName;
private String tableName;
private List<String> partVals;
private String roleName;
private List<String> colNames;
private boolean hasStats;
- private HBaseSchemaTool(String dbname, String tn, List<String> pv, String rn, List<String> cn,
- boolean s) {
+ private HBaseSchemaTool(String dbname, String tn, List<String> pv, String fn, String rn,
+ List<String> cn, boolean s) {
dbName = dbname;
tableName = tn;
partVals = pv;
+ funcName = fn;
roleName = rn;
colNames = cn;
hasStats = s;
@@ -212,6 +222,12 @@ public class HBaseSchemaTool {
}
}
+ public void function() throws IOException, TException {
+ Function func = hrw.getFunction(dbName, funcName);
+ if (func == null) System.err.println("No such function: " + dbName + "." + funcName);
+ else dump(func);
+ }
+
private void dump(TBase thriftObj) throws TException {
TMemoryBuffer buf = new TMemoryBuffer(1000);
TProtocol protocol = new TSimpleJSONProtocol(buf);
Modified: hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseStore.java
URL: http://svn.apache.org/viewvc/hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseStore.java?rev=1667338&r1=1667337&r2=1667338&view=diff
==============================================================================
--- hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseStore.java (original)
+++ hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseStore.java Tue Mar 17 15:50:31 2015
@@ -144,7 +144,7 @@ public class HBaseStore implements RawSt
return true;
} catch (IOException e) {
LOG.error("Unable to delete db" + e);
- throw new MetaException("Unable to drop database " + dbname);
+ throw new MetaException("Unable to drop database " + e.getMessage());
}
}
@@ -1492,29 +1492,57 @@ public class HBaseStore implements RawSt
@Override
public void createFunction(Function func) throws InvalidObjectException, MetaException {
- throw new UnsupportedOperationException();
+ try {
+ getHBase().putFunction(func);
+ } catch (IOException e) {
+ LOG.error("Unable to create function", e);
+ throw new MetaException("Unable to read from or write to hbase " + e.getMessage());
+ }
}
@Override
public void alterFunction(String dbName, String funcName, Function newFunction) throws
InvalidObjectException, MetaException {
- throw new UnsupportedOperationException();
+ try {
+ getHBase().putFunction(newFunction);
+ } catch (IOException e) {
+ LOG.error("Unable to alter function ", e);
+ throw new MetaException("Unable to read from or write to hbase " + e.getMessage());
+ }
}
@Override
public void dropFunction(String dbName, String funcName) throws MetaException,
NoSuchObjectException, InvalidObjectException, InvalidInputException {
- throw new UnsupportedOperationException();
+ try {
+ getHBase().deleteFunction(dbName, funcName);
+ } catch (IOException e) {
+ LOG.error("Unable to delete function" + e);
+ throw new MetaException("Unable to read from or write to hbase " + e.getMessage());
+ }
}
@Override
public Function getFunction(String dbName, String funcName) throws MetaException {
- throw new UnsupportedOperationException();
+ try {
+ return getHBase().getFunction(dbName, funcName);
+ } catch (IOException e) {
+ LOG.error("Unable to get function" + e);
+ throw new MetaException("Unable to read from or write to hbase " + e.getMessage());
+ }
}
@Override
public List<String> getFunctions(String dbName, String pattern) throws MetaException {
- throw new UnsupportedOperationException();
+ try {
+ List<Function> funcs = getHBase().scanFunctions(dbName, likeToRegex(pattern));
+ List<String> funcNames = new ArrayList<String>(funcs.size());
+ for (Function func : funcs) funcNames.add(func.getFunctionName());
+ return funcNames;
+ } catch (IOException e) {
+ LOG.error("Unable to get functions" + e);
+ throw new MetaException("Unable to read from or write to hbase " + e.getMessage());
+ }
}
@Override
Modified: hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseUtils.java
URL: http://svn.apache.org/viewvc/hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseUtils.java?rev=1667338&r1=1667337&r2=1667338&view=diff
==============================================================================
--- hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseUtils.java (original)
+++ hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseUtils.java Tue Mar 17 15:50:31 2015
@@ -34,12 +34,16 @@ import org.apache.hadoop.hive.metastore.
import org.apache.hadoop.hive.metastore.api.DecimalColumnStatsData;
import org.apache.hadoop.hive.metastore.api.DoubleColumnStatsData;
import org.apache.hadoop.hive.metastore.api.FieldSchema;
+import org.apache.hadoop.hive.metastore.api.Function;
+import org.apache.hadoop.hive.metastore.api.FunctionType;
import org.apache.hadoop.hive.metastore.api.LongColumnStatsData;
import org.apache.hadoop.hive.metastore.api.Order;
import org.apache.hadoop.hive.metastore.api.Partition;
import org.apache.hadoop.hive.metastore.api.PrincipalPrivilegeSet;
import org.apache.hadoop.hive.metastore.api.PrincipalType;
import org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo;
+import org.apache.hadoop.hive.metastore.api.ResourceType;
+import org.apache.hadoop.hive.metastore.api.ResourceUri;
import org.apache.hadoop.hive.metastore.api.Role;
import org.apache.hadoop.hive.metastore.api.SerDeInfo;
import org.apache.hadoop.hive.metastore.api.SkewedInfo;
@@ -345,7 +349,6 @@ class HBaseUtils {
Database db = new Database();
db.setName(dbName);
HbaseMetastoreProto.Database protoDb = HbaseMetastoreProto.Database.parseFrom(value);
- db.setName(dbName);
if (protoDb.hasDescription()) db.setDescription(protoDb.getDescription());
if (protoDb.hasUri()) db.setLocationUri(protoDb.getUri());
if (protoDb.hasParameters()) db.setParameters(buildParameters(protoDb.getParameters()));
@@ -372,6 +375,114 @@ class HBaseUtils {
return deserializeDatabase(dbName, value);
}
+ /**
+ * Serialize a function
+ * @param func function to serialize
+ * @return two byte arrays, first contains the key, the second the value.
+ */
+ static byte[][] serializeFunction(Function func) {
+ byte[][] result = new byte[2][];
+ result[0] = buildKey(func.getDbName(), func.getFunctionName());
+ HbaseMetastoreProto.Function.Builder builder = HbaseMetastoreProto.Function.newBuilder();
+ if (func.getClassName() != null) builder.setClassName(func.getClassName());
+ if (func.getOwnerName() != null) builder.setOwnerName(func.getOwnerName());
+ if (func.getOwnerType() != null) {
+ builder.setOwnerType(convertPrincipalTypes(func.getOwnerType()));
+ }
+ builder.setCreateTime(func.getCreateTime());
+ if (func.getFunctionType() != null) {
+ builder.setFunctionType(convertFunctionTypes(func.getFunctionType()));
+ }
+ if (func.getResourceUris() != null) {
+ for (ResourceUri uri : func.getResourceUris()) {
+ builder.addResourceUris(HbaseMetastoreProto.Function.ResourceUri.newBuilder()
+ .setResourceType(convertResourceTypes(uri.getResourceType()))
+ .setUri(uri.getUri()));
+ }
+ }
+ result[1] = builder.build().toByteArray();
+ return result;
+ }
+
+ /**
+ * Deserialize a function. This method should be used when the function and db name are
+ * already known.
+ * @param dbName name of the database the function is in
+ * @param functionName name of the function
+ * @param value serialized value of the function
+ * @return function as an object
+ * @throws InvalidProtocolBufferException
+ */
+ static Function deserializeFunction(String dbName, String functionName, byte[] value)
+ throws InvalidProtocolBufferException {
+ Function func = new Function();
+ func.setDbName(dbName);
+ func.setFunctionName(functionName);
+ HbaseMetastoreProto.Function protoFunc = HbaseMetastoreProto.Function.parseFrom(value);
+ if (protoFunc.hasClassName()) func.setClassName(protoFunc.getClassName());
+ if (protoFunc.hasOwnerName()) func.setOwnerName(protoFunc.getOwnerName());
+ if (protoFunc.hasOwnerType()) {
+ func.setOwnerType(convertPrincipalTypes(protoFunc.getOwnerType()));
+ }
+ func.setCreateTime((int)protoFunc.getCreateTime());
+ if (protoFunc.hasFunctionType()) {
+ func.setFunctionType(convertFunctionTypes(protoFunc.getFunctionType()));
+ }
+ for (HbaseMetastoreProto.Function.ResourceUri protoUri : protoFunc.getResourceUrisList()) {
+ func.addToResourceUris(new ResourceUri(convertResourceTypes(protoUri.getResourceType()),
+ protoUri.getUri()));
+ }
+ return func;
+ }
+
+ /**
+ * Deserialize a function. This method should be used when the dbname and function name are
+ * not already known, such as in a scan.
+ * @param key key from hbase
+ * @param value value from hbase
+ * @return function object
+ * @throws InvalidProtocolBufferException
+ */
+ static Function deserializeFunction(byte[] key, byte[] value)
+ throws InvalidProtocolBufferException {
+ String[] keys = deserializeKey(key);
+ return deserializeFunction(keys[0], keys[1], value);
+ }
+
+ private static HbaseMetastoreProto.Function.FunctionType convertFunctionTypes(FunctionType type) {
+ switch (type) {
+ case JAVA: return HbaseMetastoreProto.Function.FunctionType.JAVA;
+ default: throw new RuntimeException("Unknown function type " + type.toString());
+ }
+ }
+
+ private static FunctionType convertFunctionTypes(HbaseMetastoreProto.Function.FunctionType type) {
+ switch (type) {
+ case JAVA: return FunctionType.JAVA;
+ default: throw new RuntimeException("Unknown function type " + type.toString());
+ }
+ }
+
+ private static HbaseMetastoreProto.Function.ResourceUri.ResourceType
+ convertResourceTypes(ResourceType type) {
+ switch (type) {
+ case JAR: return HbaseMetastoreProto.Function.ResourceUri.ResourceType.JAR;
+ case FILE: return HbaseMetastoreProto.Function.ResourceUri.ResourceType.FILE;
+ case ARCHIVE: return HbaseMetastoreProto.Function.ResourceUri.ResourceType.ARCHIVE;
+ default: throw new RuntimeException("Unknown resource type " + type.toString());
+ }
+ }
+
+ private static ResourceType convertResourceTypes(
+ HbaseMetastoreProto.Function.ResourceUri.ResourceType type) {
+ switch (type) {
+ case JAR: return ResourceType.JAR;
+ case FILE: return ResourceType.FILE;
+ case ARCHIVE: return ResourceType.ARCHIVE;
+ default: throw new RuntimeException("Unknown resource type " + type.toString());
+ }
+ }
+
private static List<FieldSchema>
convertFieldSchemaListFromProto(List<HbaseMetastoreProto.FieldSchema> protoList) {
List<FieldSchema> schemas = new ArrayList<FieldSchema>(protoList.size());
Modified: hive/branches/hbase-metastore/metastore/src/protobuf/org/apache/hadoop/hive/metastore/hbase/hbase_metastore_proto.proto
URL: http://svn.apache.org/viewvc/hive/branches/hbase-metastore/metastore/src/protobuf/org/apache/hadoop/hive/metastore/hbase/hbase_metastore_proto.proto?rev=1667338&r1=1667337&r2=1667338&view=diff
==============================================================================
--- hive/branches/hbase-metastore/metastore/src/protobuf/org/apache/hadoop/hive/metastore/hbase/hbase_metastore_proto.proto (original)
+++ hive/branches/hbase-metastore/metastore/src/protobuf/org/apache/hadoop/hive/metastore/hbase/hbase_metastore_proto.proto Tue Mar 17 15:50:31 2015
@@ -65,8 +65,6 @@ message ColumnStats {
optional DecimalStats decimal_stats = 10;
}
-
-
message Database {
optional string description = 1;
optional string uri = 2;
@@ -82,6 +80,29 @@ message FieldSchema {
optional string comment = 3;
}
+message Function {
+ enum FunctionType {
+ JAVA = 1;
+ }
+
+ message ResourceUri {
+ enum ResourceType {
+ JAR = 1;
+ FILE = 2;
+ ARCHIVE = 3;
+ }
+ required ResourceType resource_type = 1;
+ required string uri = 2;
+ }
+
+ optional string class_name = 1;
+ optional string owner_name = 2;
+ optional PrincipalType owner_type = 3;
+ optional sint64 create_time = 4;
+ optional FunctionType function_type = 5;
+ repeated ResourceUri resource_uris = 6;
+}
+
message ParameterEntry {
required string key = 1;
required string value = 2;
Modified: hive/branches/hbase-metastore/metastore/src/test/org/apache/hadoop/hive/metastore/hbase/TestHBaseStore.java
URL: http://svn.apache.org/viewvc/hive/branches/hbase-metastore/metastore/src/test/org/apache/hadoop/hive/metastore/hbase/TestHBaseStore.java?rev=1667338&r1=1667337&r2=1667338&view=diff
==============================================================================
--- hive/branches/hbase-metastore/metastore/src/test/org/apache/hadoop/hive/metastore/hbase/TestHBaseStore.java (original)
+++ hive/branches/hbase-metastore/metastore/src/test/org/apache/hadoop/hive/metastore/hbase/TestHBaseStore.java Tue Mar 17 15:50:31 2015
@@ -42,10 +42,15 @@ import org.apache.hadoop.hive.metastore.
import org.apache.hadoop.hive.metastore.api.DecimalColumnStatsData;
import org.apache.hadoop.hive.metastore.api.DoubleColumnStatsData;
import org.apache.hadoop.hive.metastore.api.FieldSchema;
+import org.apache.hadoop.hive.metastore.api.Function;
+import org.apache.hadoop.hive.metastore.api.FunctionType;
import org.apache.hadoop.hive.metastore.api.LongColumnStatsData;
import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
import org.apache.hadoop.hive.metastore.api.Order;
import org.apache.hadoop.hive.metastore.api.Partition;
+import org.apache.hadoop.hive.metastore.api.PrincipalType;
+import org.apache.hadoop.hive.metastore.api.ResourceType;
+import org.apache.hadoop.hive.metastore.api.ResourceUri;
import org.apache.hadoop.hive.metastore.api.Role;
import org.apache.hadoop.hive.metastore.api.SerDeInfo;
import org.apache.hadoop.hive.metastore.api.SkewedInfo;
@@ -136,6 +141,70 @@ public class TestHBaseStore {
}
@Test
+ public void createFunction() throws Exception {
+ String dbname = "default";
+ String funcName = "createfunc";
+ int now = (int)(System.currentTimeMillis()/ 1000);
+ Function func = new Function(funcName, dbname, "o.a.h.h.myfunc", "me", PrincipalType.USER,
+ now, FunctionType.JAVA, Arrays.asList(new ResourceUri(ResourceType.JAR,
+ "file:/tmp/somewhere")));
+ store.createFunction(func);
+
+ Function f = store.getFunction(dbname, funcName);
+ Assert.assertEquals(dbname, f.getDbName());
+ Assert.assertEquals(funcName, f.getFunctionName());
+ Assert.assertEquals("o.a.h.h.myfunc", f.getClassName());
+ Assert.assertEquals("me", f.getOwnerName());
+ Assert.assertEquals(PrincipalType.USER, f.getOwnerType());
+ Assert.assertTrue(now <= f.getCreateTime());
+ Assert.assertEquals(FunctionType.JAVA, f.getFunctionType());
+ Assert.assertEquals(1, f.getResourceUrisSize());
+ Assert.assertEquals(ResourceType.JAR, f.getResourceUris().get(0).getResourceType());
+ Assert.assertEquals("file:/tmp/somewhere", f.getResourceUris().get(0).getUri());
+ }
+
+ @Test
+ public void alterFunction() throws Exception {
+ String dbname = "default";
+ String funcName = "alterfunc";
+ int now = (int)(System.currentTimeMillis()/ 1000);
+ List<ResourceUri> uris = new ArrayList<ResourceUri>();
+ uris.add(new ResourceUri(ResourceType.FILE, "whatever"));
+ Function func = new Function(funcName, dbname, "o.a.h.h.myfunc", "me", PrincipalType.USER,
+ now, FunctionType.JAVA, uris);
+ store.createFunction(func);
+
+ Function f = store.getFunction(dbname, funcName);
+ Assert.assertEquals(ResourceType.FILE, f.getResourceUris().get(0).getResourceType());
+
+ func.addToResourceUris(new ResourceUri(ResourceType.ARCHIVE, "file"));
+ store.alterFunction(dbname, funcName, func);
+
+ f = store.getFunction(dbname, funcName);
+ Assert.assertEquals(2, f.getResourceUrisSize());
+ Assert.assertEquals(ResourceType.FILE, f.getResourceUris().get(0).getResourceType());
+ Assert.assertEquals(ResourceType.ARCHIVE, f.getResourceUris().get(1).getResourceType());
+
+ }
+
+ @Test
+ public void dropFunction() throws Exception {
+ String dbname = "default";
+ String funcName = "delfunc";
+ int now = (int)(System.currentTimeMillis()/ 1000);
+ Function func = new Function(funcName, dbname, "o.a.h.h.myfunc", "me", PrincipalType.USER,
+ now, FunctionType.JAVA, Arrays.asList(new ResourceUri(ResourceType.JAR, "file:/tmp/somewhere")));
+ store.createFunction(func);
+
+ Function f = store.getFunction(dbname, funcName);
+ Assert.assertNotNull(f);
+
+ store.dropFunction(dbname, funcName);
+ //thrown.expect(NoSuchObjectException.class);
+ Assert.assertNull(store.getFunction(dbname, funcName));
+ }
+
+ @Test
public void createTable() throws Exception {
String tableName = "mytable";
int startTime = (int)(System.currentTimeMillis() / 1000);