org.apache.hadoop.hive.metastore.api.Function类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(15.2k)|赞(0)|评价(0)|浏览(155)

本文整理了Java中org.apache.hadoop.hive.metastore.api.Function类的一些代码示例,展示了Function类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Function类的具体详情如下:
包路径:org.apache.hadoop.hive.metastore.api.Function
类名称:Function

Function介绍

暂无

代码示例

代码示例来源:origin: apache/hive

public Object getFieldValue(_Fields field) {
 switch (field) {
 case FUNCTION_NAME:
  return getFunctionName();
 case DB_NAME:
  return getDbName();
 case CLASS_NAME:
  return getClassName();
 case OWNER_NAME:
  return getOwnerName();
 case OWNER_TYPE:
  return getOwnerType();
 case CREATE_TIME:
  return getCreateTime();
 case FUNCTION_TYPE:
  return getFunctionType();
 case RESOURCE_URIS:
  return getResourceUris();
 case CAT_NAME:
  return getCatName();
 }
 throw new IllegalStateException();
}

代码示例来源:origin: apache/hive

@Test
public void testCreateFunctionDefaultValues() throws Exception {
 Function function = new Function();
 function.setDbName(OTHER_DATABASE);
 function.setFunctionName("test_function");
 function.setClassName(TEST_FUNCTION_CLASS);
 function.setOwnerType(PrincipalType.USER);
 function.setFunctionType(FunctionType.JAVA);
 client.createFunction(function);
 Function createdFunction = client.getFunction(function.getDbName(),
   function.getFunctionName());
 Assert.assertNull("Comparing OwnerName", createdFunction.getOwnerName());
 Assert.assertEquals("Comparing ResourceUris", 0, createdFunction.getResourceUris().size());
 // The create time is set
 Assert.assertNotEquals("Comparing CreateTime", 0, createdFunction.getCreateTime());
}

代码示例来源:origin: apache/hive

case FUNCTION_NAME:
 if (value == null) {
  unsetFunctionName();
 } else {
  setFunctionName((String)value);
  unsetDbName();
 } else {
  setDbName((String)value);
  unsetClassName();
 } else {
  setClassName((String)value);
  unsetOwnerName();
 } else {
  setOwnerName((String)value);
  unsetOwnerType();
 } else {
  setOwnerType((PrincipalType)value);
  unsetCreateTime();
 } else {
  setCreateTime((Integer)value);
  unsetFunctionType();
 } else {
  setFunctionType((FunctionType)value);

代码示例来源:origin: apache/hive

public JSONDropFunctionMessage(String server, String servicePrincipal, Function fn, Long timestamp) {
 this.server = server;
 this.servicePrincipal = servicePrincipal;
 this.db = fn.getDbName();
 this.functionName = fn.getFunctionName();
 this.timestamp = timestamp;
 checkValid();
}

代码示例来源:origin: apache/hive

.addResourceUri(new ResourceUri(ResourceType.ARCHIVE, "hdfs:///tmp/archive1.tgz"))
    .build(conf);
function.unsetCatName();
client.createFunction(function);
Function createdFunction = client.getFunction(dbName, functionName);
Assert.assertEquals(function.getFunctionName(), createdFunction.getFunctionName());
Assert.assertEquals(function.getDbName(), createdFunction.getDbName());
Assert.assertEquals(expectedCatalog(), createdFunction.getCatName());
Assert.assertEquals(function.getClassName(), createdFunction.getClassName());
Assert.assertEquals(function.getOwnerName(), createdFunction.getOwnerName());
Assert.assertEquals(function.getOwnerType(), createdFunction.getOwnerType());
Assert.assertEquals(function.getFunctionType(), createdFunction.getFunctionType());
Assert.assertEquals(function.getResourceUris(), createdFunction.getResourceUris());
  .setClass(TEST_FUNCTION_CLASS)
  .build(conf);
f2.unsetCatName();
client.createFunction(f2);
Assert.assertFalse(functions.contains(f2Name));
client.dropFunction(function.getDbName(), function.getFunctionName());
try {
 client.getFunction(function.getDbName(), function.getFunctionName());
 Assert.fail("Expected a NoSuchObjectException to be thrown");
} catch (NoSuchObjectException exception) {

代码示例来源:origin: apache/hive

public void reloadFunctions() throws HiveException {
 HashSet<String> registryFunctions = new HashSet<String>(
   FunctionRegistry.getFunctionNames(".+\\..+"));
 for (Function function : getAllFunctions()) {
  String functionName = function.getFunctionName();
  try {
   LOG.info("Registering function " + functionName + " " + function.getClassName());
   String qualFunc = FunctionUtils.qualifyFunctionName(functionName, function.getDbName());
   FunctionRegistry.registerPermanentFunction(qualFunc, function.getClassName(), false,
         FunctionTask.toFunctionResource(function.getResourceUris()));
   registryFunctions.remove(qualFunc);
  } catch (Exception e) {
   LOG.warn("Failed to register persistent function " +
       functionName + ":" + function.getClassName() + ". Ignore and continue.");
  }
 }
 // unregister functions from local system registry that are not in getAllFunctions()
 for (String functionName : registryFunctions) {
  try {
   FunctionRegistry.unregisterPermanentFunction(functionName);
  } catch (Exception e) {
   LOG.warn("Failed to unregister persistent function " +
     functionName + "on reload. Ignore and continue.");
  }
 }
}

代码示例来源:origin: apache/hive

client.alterFunction(testFunctions[0].getDbName(), testFunctions[0].getFunctionName(),
  newFunction);
Function alteredFunction = client.getFunction(newFunction.getDbName(),
  newFunction.getFunctionName());
Assert.assertEquals("Comparing Database", newFunction.getDbName(),
  alteredFunction.getDbName());
Assert.assertEquals("Comparing FunctionName", newFunction.getFunctionName(),
  alteredFunction.getFunctionName());
Assert.assertEquals("Comparing OwnerName", newFunction.getOwnerName(),
  alteredFunction.getOwnerName());
Assert.assertEquals("Comparing OwnerType", newFunction.getOwnerType(),
  alteredFunction.getOwnerType());
Assert.assertEquals("Comparing ClassName", newFunction.getClassName(),
  alteredFunction.getClassName());
Assert.assertEquals("Comparing FunctionType", newFunction.getFunctionType(),
  alteredFunction.getFunctionType());
try {
 client.getFunction(testFunctions[0].getDbName(), testFunctions[0].getDbName());
 Assert.fail("Expected a NoSuchObjectException to be thrown");
} catch (NoSuchObjectException exception) {
newFunction = testFunctions[1].deepCopy();
newFunction.setClassName("NewClassName");
client.alterFunction(testFunctions[1].getDbName(), testFunctions[1].getFunctionName(),
  newFunction);

代码示例来源:origin: apache/hive

client.dropDatabase(OTHER_DATABASE, true, true, true);
for(Function function : client.getAllFunctions().getFunctions()) {
 client.dropFunction(function.getDbName(), function.getFunctionName());
 client.createFunction(testFunctions[i]);
 testFunctions[i] = client.getFunction(testFunctions[i].getDbName(),
   testFunctions[i].getFunctionName());

代码示例来源:origin: apache/hive

private void validateFunctionInfo(Function func) throws InvalidObjectException, MetaException {
 if (func == null) {
  throw new MetaException("Function cannot be null.");
 }
 if (func.getFunctionName() == null) {
  throw new MetaException("Function name cannot be null.");
 }
 if (func.getDbName() == null) {
  throw new MetaException("Database name in Function cannot be null.");
 }
 if (!MetaStoreUtils.validateName(func.getFunctionName(), null)) {
  throw new InvalidObjectException(func.getFunctionName() + " is not a valid object name");
 }
 String className = func.getClassName();
 if (className == null) {
  throw new InvalidObjectException("Function class name cannot be null");
 }
 if (func.getOwnerType() == null) {
  throw new MetaException("Function owner type cannot be null.");
 }
 if (func.getFunctionType() == null) {
  throw new MetaException("Function type cannot be null.");
 }
}

代码示例来源:origin: apache/hive

.setLocation(MetaStoreTestUtils.getTestWarehouseDir(catName))
  .build();
client.createCatalog(cat);
    .create(client, metaStore.getConf());
Function createdFunction = client.getFunction(catName, dbName, functionName);
function.setCreateTime(createdFunction.getCreateTime());
Assert.assertEquals("Comparing functions", function, createdFunction);
  .create(client, metaStore.getConf());
Set<String> functions = new HashSet<>(client.getFunctions(catName, dbName, "test*"));
Assert.assertEquals(2, functions.size());
Assert.assertTrue(functions.contains(functionName));
Assert.assertFalse(functions.contains(f2Name));
client.dropFunction(function.getCatName(), function.getDbName(), function.getFunctionName());
try {
 client.getFunction(function.getCatName(), function.getDbName(), function.getFunctionName());
 Assert.fail("Expected a NoSuchObjectException to be thrown");
} catch (NoSuchObjectException exception) {

代码示例来源:origin: apache/hive

client.alterFunction(originalFunction.getDbName().toUpperCase(),
  originalFunction.getFunctionName().toUpperCase(), newFunction);
Function alteredFunction = client.getFunction(newFunction.getDbName(),
  newFunction.getFunctionName());
newFunction.setCreateTime(alteredFunction.getCreateTime());
Assert.assertEquals("Comparing functions", newFunction, alteredFunction);
try {
 client.getFunction(originalFunction.getDbName(), originalFunction.getDbName());
 Assert.fail("Expected a NoSuchObjectException to be thrown");
} catch (NoSuchObjectException exception) {
newFunction.setFunctionName("test_function_3");
client.alterFunction("DeFaUlt", "tEsT_FuncTION_HiDDEn_1", newFunction);
alteredFunction = client.getFunction(newFunction.getDbName(), newFunction.getFunctionName());
newFunction.setCreateTime(alteredFunction.getCreateTime());
Assert.assertEquals("Comparing functions", newFunction, alteredFunction);
try {
 client.getFunction(originalFunction.getDbName(), originalFunction.getDbName());
 Assert.fail("Expected a NoSuchObjectException to be thrown");
} catch (NoSuchObjectException exception) {

代码示例来源:origin: apache/hive

Map<String, String> transactionalListenerResponses = Collections.emptyMap();
try {
 String catName = func.isSetCatName() ? func.getCatName() : getDefaultCatalog(conf);
 ms.openTransaction();
 Database db = ms.getDatabase(catName, func.getDbName());
 if (db == null) {
  throw new NoSuchObjectException("The database " + func.getDbName() + " does not exist");
 Function existingFunc = ms.getFunction(catName, func.getDbName(), func.getFunctionName());
 if (existingFunc != null) {
  throw new AlreadyExistsException(
    "Function " + func.getFunctionName() + " already exists");
 func.setCreateTime((int) time);
 ms.createFunction(func);
 if (!transactionalListeners.isEmpty()) {

代码示例来源:origin: stackoverflow.com

var multiply = new Function("x", "y", "return x * y;");

代码示例来源:origin: apache/hive

.create(client, metaStore.getConf());
Function createdFunction = client.getFunction(function.getDbName(),
  function.getFunctionName());
function.setCreateTime(createdFunction.getCreateTime());
Assert.assertEquals("Comparing functions", function, createdFunction);
client.dropFunction(function.getDbName(), function.getFunctionName());
try {
 client.getFunction(function.getDbName(), function.getFunctionName());
 Assert.fail("Expected a NoSuchObjectException to be thrown");
} catch (NoSuchObjectException exception) {

代码示例来源:origin: apache/hive

@Test
public void testDropFunctionCaseInsensitive() throws Exception {
 Function function = testFunctions[0];
 // Test in upper case
 client.dropFunction(function.getDbName().toUpperCase(),
   function.getFunctionName().toUpperCase());
 // Check if the function is really removed
 try {
  client.getFunction(function.getDbName(), function.getFunctionName());
  Assert.fail("Expected a NoSuchObjectException to be thrown");
 } catch (NoSuchObjectException exception) {
  // Expected exception
 }
 // Test in mixed case
 client.createFunction(function);
 client.dropFunction("DeFaUlt", "tEsT_FuncTION_tO_FinD_1");
 // Check if the function is really removed
 try {
  client.getFunction(function.getDbName(), function.getFunctionName());
  Assert.fail("Expected a NoSuchObjectException to be thrown");
 } catch (NoSuchObjectException exception) {
  // Expected exception
 }
}

代码示例来源:origin: apache/hive

private CreateFunctionDesc build() throws SemanticException {
  replCopyTasks.clear();
  PrimaryToReplicaResourceFunction conversionFunction =
    new PrimaryToReplicaResourceFunction(context, metadata, destinationDbName);
  // We explicitly create immutable lists here as it forces the guava lib to run the transformations
  // and not do them lazily. The reason being the function class used for transformations additionally
  // also creates the corresponding replCopyTasks, which cannot be evaluated lazily. since the query
  // plan needs to be complete before we execute and not modify it while execution in the driver.
  List<ResourceUri> transformedUris = ImmutableList.copyOf(
    Lists.transform(metadata.function.getResourceUris(), conversionFunction)
  );
  replCopyTasks.addAll(conversionFunction.replCopyTasks);
  String fullQualifiedFunctionName = FunctionUtils.qualifyFunctionName(
    metadata.function.getFunctionName(), destinationDbName
  );
  // For bootstrap load, the create function should be always performed.
  // Only for incremental load, need to validate if event is newer than the database.
  ReplicationSpec replSpec = (context.dmd == null) ? null : context.eventOnlyReplicationSpec();
  return new CreateFunctionDesc(
      fullQualifiedFunctionName, false, metadata.function.getClassName(),
      transformedUris, replSpec
  );
 }
}

代码示例来源:origin: com.facebook.presto.hive/hive-apache

@Override
public void create_function(Function func) throws AlreadyExistsException,
  InvalidObjectException, MetaException, NoSuchObjectException,
  TException {
 validateFunctionInfo(func);
 boolean success = false;
 RawStore ms = getMS();
 try {
  ms.openTransaction();
  Database db = ms.getDatabase(func.getDbName());
  if (db == null) {
   throw new NoSuchObjectException("The database " + func.getDbName() + " does not exist");
  }
  Function existingFunc = ms.getFunction(func.getDbName(), func.getFunctionName());
  if (existingFunc != null) {
   throw new AlreadyExistsException(
     "Function " + func.getFunctionName() + " already exists");
  }
  // set create time
  long time = System.currentTimeMillis() / 1000;
  func.setCreateTime((int) time);
  ms.createFunction(func);
  success = ms.commitTransaction();
 } finally {
  if (!success) {
   ms.rollbackTransaction();
  }
 }
}

代码示例来源:origin: apache/hive

@Test(expected = MetaException.class)
public void testAlterFunctionAlreadyExists() throws Exception {
 Function originalFunction = testFunctions[0];
 Function newFunction = testFunctions[1];
 client.alterFunction(originalFunction.getDbName(), originalFunction.getFunctionName(),
   newFunction);
}

代码示例来源:origin: org.apache.hive/hive-standalone-metastore

private void validateFunctionInfo(Function func) throws InvalidObjectException, MetaException {
 if (!MetaStoreUtils.validateName(func.getFunctionName(), null)) {
  throw new InvalidObjectException(func.getFunctionName() + " is not a valid object name");
 }
 String className = func.getClassName();
 if (className == null) {
  throw new InvalidObjectException("Function class name cannot be null");
 }
}

代码示例来源:origin: apache/hive

@Test
public void testGetAllFunctions() throws Exception {
 GetAllFunctionsResponse response = client.getAllFunctions();
 List<Function> allFunctions = response.getFunctions();
 Assert.assertEquals("All functions size", 4, allFunctions.size());
 for(Function function : allFunctions) {
  if (function.getDbName().equals(OTHER_DATABASE)) {
   Assert.assertEquals("Comparing functions", testFunctions[3], function);
  } else if (function.getFunctionName().equals("test_function_hidden_1")) {
   Assert.assertEquals("Comparing functions", testFunctions[2], function);
  } else if (function.getFunctionName().equals("test_function_to_find_2")) {
   Assert.assertEquals("Comparing functions", testFunctions[1], function);
  } else {
 client.dropFunction(testFunctions[1].getDbName(), testFunctions[1].getFunctionName());
 response = client.getAllFunctions();
 allFunctions = response.getFunctions();
 Assert.assertEquals("All functions size", 3, allFunctions.size());
 for(Function function : allFunctions) {
  if (function.getDbName().equals(OTHER_DATABASE)) {
   Assert.assertEquals("Comparing functions", testFunctions[3], function);
  } else if (function.getFunctionName().equals("test_function_hidden_1")) {
   Assert.assertEquals("Comparing functions", testFunctions[2], function);
  } else {

相关文章