Search in sources :

Example 1 with MSerDeInfo

use of org.apache.hadoop.hive.metastore.model.MSerDeInfo in project hive by apache.

the class ObjectStore method updateSerdeURI.

/**
 * The following APIs
 *
 *  - updateSerdeURI
 *
 * is used by HiveMetaTool. This API **shouldn't** be exposed via Thrift.
 */
public UpdateSerdeURIRetVal updateSerdeURI(URI oldLoc, URI newLoc, String serdeProp, boolean isDryRun) {
    boolean committed = false;
    Query query = null;
    Map<String, String> updateLocations = new HashMap<>();
    List<String> badRecords = new ArrayList<>();
    UpdateSerdeURIRetVal retVal = null;
    try {
        openTransaction();
        query = pm.newQuery(MSerDeInfo.class);
        List<MSerDeInfo> mSerdes = (List<MSerDeInfo>) query.execute();
        pm.retrieveAll(mSerdes);
        for (MSerDeInfo mSerde : mSerdes) {
            if (mSerde.getParameters().containsKey(serdeProp)) {
                String schemaLoc = mSerde.getParameters().get(serdeProp);
                URI schemaLocURI = null;
                try {
                    schemaLocURI = new Path(schemaLoc).toUri();
                } catch (IllegalArgumentException e) {
                    badRecords.add(schemaLoc);
                }
                if (schemaLocURI == null) {
                    badRecords.add(schemaLoc);
                } else {
                    if (shouldUpdateURI(schemaLocURI, oldLoc)) {
                        String newSchemaLoc = schemaLoc.replaceAll(oldLoc.toString(), newLoc.toString());
                        updateLocations.put(schemaLocURI.toString(), newSchemaLoc);
                        if (!isDryRun) {
                            mSerde.getParameters().put(serdeProp, newSchemaLoc);
                        }
                    }
                }
            }
        }
        committed = commitTransaction();
        if (committed) {
            retVal = new UpdateSerdeURIRetVal(badRecords, updateLocations);
        }
        return retVal;
    } finally {
        rollbackAndCleanup(committed, query);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Query(javax.jdo.Query) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(java.net.URI) LinkedList(java.util.LinkedList) MStringList(org.apache.hadoop.hive.metastore.model.MStringList) ArrayList(java.util.ArrayList) List(java.util.List) MSerDeInfo(org.apache.hadoop.hive.metastore.model.MSerDeInfo)

Example 2 with MSerDeInfo

use of org.apache.hadoop.hive.metastore.model.MSerDeInfo in project hive by apache.

the class ObjectStore method getSerDeInfo.

@Override
public SerDeInfo getSerDeInfo(String serDeName) throws NoSuchObjectException, MetaException {
    boolean committed = false;
    try {
        openTransaction();
        MSerDeInfo mSerDeInfo = getMSerDeInfo(serDeName);
        if (mSerDeInfo == null) {
            throw new NoSuchObjectException("No SerDe named " + serDeName);
        }
        SerDeInfo serde = convertToSerDeInfo(mSerDeInfo);
        committed = commitTransaction();
        return serde;
    } finally {
        if (!committed)
            rollbackTransaction();
        ;
    }
}
Also used : MSerDeInfo(org.apache.hadoop.hive.metastore.model.MSerDeInfo) SerDeInfo(org.apache.hadoop.hive.metastore.api.SerDeInfo) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MSerDeInfo(org.apache.hadoop.hive.metastore.model.MSerDeInfo)

Example 3 with MSerDeInfo

use of org.apache.hadoop.hive.metastore.model.MSerDeInfo in project hive by apache.

the class ObjectStore method getMSerDeInfo.

private MSerDeInfo getMSerDeInfo(String serDeName) throws MetaException {
    Query query = null;
    try {
        query = pm.newQuery(MSerDeInfo.class, "name == serDeName");
        query.declareParameters("java.lang.String serDeName");
        query.setUnique(true);
        MSerDeInfo mSerDeInfo = (MSerDeInfo) query.execute(serDeName);
        pm.retrieve(mSerDeInfo);
        return mSerDeInfo;
    } finally {
        if (query != null)
            query.closeAll();
    }
}
Also used : Query(javax.jdo.Query) MSerDeInfo(org.apache.hadoop.hive.metastore.model.MSerDeInfo)

Example 4 with MSerDeInfo

use of org.apache.hadoop.hive.metastore.model.MSerDeInfo in project hive by apache.

the class ObjectStore method addSerde.

@Override
public void addSerde(SerDeInfo serde) throws AlreadyExistsException, MetaException {
    boolean committed = false;
    try {
        openTransaction();
        if (getMSerDeInfo(serde.getName()) != null) {
            throw new AlreadyExistsException("Serde with name " + serde.getName() + " already exists");
        }
        MSerDeInfo mSerde = convertToMSerDeInfo(serde);
        pm.makePersistent(mSerde);
        committed = commitTransaction();
    } finally {
        if (!committed)
            rollbackTransaction();
    }
}
Also used : AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) MSerDeInfo(org.apache.hadoop.hive.metastore.model.MSerDeInfo)

Aggregations

MSerDeInfo (org.apache.hadoop.hive.metastore.model.MSerDeInfo)4 Query (javax.jdo.Query)2 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Path (org.apache.hadoop.fs.Path)1 AlreadyExistsException (org.apache.hadoop.hive.metastore.api.AlreadyExistsException)1 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)1 SerDeInfo (org.apache.hadoop.hive.metastore.api.SerDeInfo)1 MStringList (org.apache.hadoop.hive.metastore.model.MStringList)1