public class HiveTemplate extends java.lang.Object implements org.springframework.beans.factory.InitializingBean, HiveOperations, org.springframework.context.ResourceLoaderAware
HiveClient
and converts Hive exceptions into DataAccessExceptions.Constructor and Description |
---|
HiveTemplate()
Constructs a new
HiveClient instance. |
HiveTemplate(HiveClientFactory hiveClientFactory)
Constructs a new
HiveTemplate instance. |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
protected org.springframework.dao.DataAccessException |
convertHiveAccessException(java.lang.Exception ex)
Converts the given Hive exception to an appropriate exception from the org.springframework.dao hierarchy.
|
protected HiveClient |
createHiveClient() |
<T> T |
execute(HiveClientCallback<T> action)
Executes the action specified by the given callback object within an active connection.
|
java.util.List<java.lang.String> |
executeScript(HiveScript script)
Executes a Hive script.
|
java.util.List<java.lang.String> |
executeScript(java.lang.Iterable<HiveScript> scripts)
Executes multiple Hive scripts.
|
java.util.List<java.lang.String> |
query(java.lang.String query)
Executes the given HiveQL that results in a list of objects.
|
java.util.List<java.lang.String> |
query(java.lang.String query,
java.util.Map<?,?> arguments)
Executes the given HiveQL using the list of arguments, expecting a list of objects.
|
java.lang.Integer |
queryForInt(java.lang.String query)
Executes the given HiveQL that results in a single int value.
|
java.lang.Integer |
queryForInt(java.lang.String query,
java.util.Map<?,?> arguments)
Executes the given HiveQL using the list of arguments, that results in a single int value.
|
java.lang.Long |
queryForLong(java.lang.String query)
Executes the given HiveQL that results in a single long value.
|
java.lang.Long |
queryForLong(java.lang.String query,
java.util.Map<?,?> arguments)
Executes the given HiveQL using the list of arguments, that results in a single long value.
|
java.lang.String |
queryForString(java.lang.String query)
Executes the given HiveQL that results in a single object.
|
java.lang.String |
queryForString(java.lang.String query,
java.util.Map<?,?> arguments)
Executes the given HiveQL using the list of arguments, that results in a single object.
|
void |
setHiveClientFactory(HiveClientFactory hiveClientFactory)
Sets the
HiveClient factory. |
void |
setResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader) |
public HiveTemplate()
HiveClient
instance.
Expects setHiveClientFactory(HiveClientFactory)
to be called before using it.public HiveTemplate(HiveClientFactory hiveClientFactory)
HiveTemplate
instance.hiveClientFactory
- HiveClient factorypublic void afterPropertiesSet()
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
public <T> T execute(HiveClientCallback<T> action) throws org.springframework.dao.DataAccessException
execute
in interface HiveOperations
T
- action typeaction
- callback object that specifies the Hive actionorg.springframework.dao.DataAccessException
- exceptionprotected org.springframework.dao.DataAccessException convertHiveAccessException(java.lang.Exception ex)
ex
- hive exceptionpublic java.util.List<java.lang.String> query(java.lang.String query) throws org.springframework.dao.DataAccessException
query
in interface HiveOperations
query
- HiveQLorg.springframework.dao.DataAccessException
- exceptionpublic java.util.List<java.lang.String> query(java.lang.String query, java.util.Map<?,?> arguments) throws org.springframework.dao.DataAccessException
query
in interface HiveOperations
query
- HiveQLarguments
- query argumentsorg.springframework.dao.DataAccessException
- exceptionpublic java.lang.String queryForString(java.lang.String query) throws org.springframework.dao.DataAccessException
queryForString
in interface HiveOperations
query
- HiveQLorg.springframework.dao.DataAccessException
- exceptionpublic java.lang.String queryForString(java.lang.String query, java.util.Map<?,?> arguments) throws org.springframework.dao.DataAccessException
queryForString
in interface HiveOperations
query
- HiveQLarguments
- query argumentsorg.springframework.dao.DataAccessException
- exceptionpublic java.lang.Integer queryForInt(java.lang.String query) throws org.springframework.dao.DataAccessException
queryForInt
in interface HiveOperations
query
- HiveQLorg.springframework.dao.DataAccessException
- exceptionpublic java.lang.Integer queryForInt(java.lang.String query, java.util.Map<?,?> arguments) throws org.springframework.dao.DataAccessException
queryForInt
in interface HiveOperations
query
- HiveQLarguments
- query argumentsorg.springframework.dao.DataAccessException
- exceptionpublic java.lang.Long queryForLong(java.lang.String query) throws org.springframework.dao.DataAccessException
queryForLong
in interface HiveOperations
query
- HiveQLorg.springframework.dao.DataAccessException
- exceptionpublic java.lang.Long queryForLong(java.lang.String query, java.util.Map<?,?> arguments) throws org.springframework.dao.DataAccessException
queryForLong
in interface HiveOperations
query
- HiveQLarguments
- query argumentsorg.springframework.dao.DataAccessException
- exceptionpublic java.util.List<java.lang.String> executeScript(HiveScript script) throws org.springframework.dao.DataAccessException
executeScript
in interface HiveOperations
script
- script resource and argumentsorg.springframework.dao.DataAccessException
- exceptionpublic java.util.List<java.lang.String> executeScript(java.lang.Iterable<HiveScript> scripts) throws org.springframework.dao.DataAccessException
executeScript
in interface HiveOperations
scripts
- scripts resources and argumentsorg.springframework.dao.DataAccessException
- exceptionprotected HiveClient createHiveClient()
public void setHiveClientFactory(HiveClientFactory hiveClientFactory)
HiveClient
factory.hiveClientFactory
- hive client factory to setpublic void setResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader)
setResourceLoader
in interface org.springframework.context.ResourceLoaderAware