Search in sources :

Example 96 with SemanticException

use of org.apache.hadoop.hive.ql.parse.SemanticException in project hive by apache.

the class LoadTable method tasks.

public TaskTracker tasks() throws SemanticException {
    // or are both specified, in which case, that's what we are intended to create the new table as.
    try {
        if (event.shouldNotReplicate()) {
            return tracker;
        }
        // this can never be null or empty;
        String dbName = tableContext.dbNameToLoadIn;
        // Create table associated with the import
        // Executed if relevant, and used to contain all the other details about the table if not.
        ImportTableDesc tableDesc = tableContext.overrideProperties(event.tableDesc(dbName));
        Table table = ImportSemanticAnalyzer.tableIfExists(tableDesc, context.hiveDb);
        ReplicationSpec replicationSpec = event.replicationSpec();
        // Normally, on import, trying to create a table or a partition in a db that does not yet exist
        // is a error condition. However, in the case of a REPL LOAD, it is possible that we are trying
        // to create tasks to create a table inside a db that as-of-now does not exist, but there is
        // a precursor Task waiting that will create it before this is encountered. Thus, we instantiate
        // defaults and do not error out in that case.
        // the above will change now since we are going to split replication load in multiple execution
        // tasks and hence we could have created the database earlier in which case the waitOnPrecursor will
        // be false and hence if db Not found we should error out.
        Database parentDb = context.hiveDb.getDatabase(tableDesc.getDatabaseName());
        if (parentDb == null) {
            if (!tableContext.waitOnPrecursor()) {
                throw new SemanticException(ErrorMsg.DATABASE_NOT_EXISTS.getMsg(tableDesc.getDatabaseName()));
            }
        }
        if (table == null) {
            // If table doesn't exist, allow creating a new one only if the database state is older than the update.
            if ((parentDb != null) && (!replicationSpec.allowReplacementInto(parentDb.getParameters()))) {
                // If the target table exists and is newer or same as current update based on repl.last.id, then just noop it.
                return tracker;
            }
        } else {
            if (!replicationSpec.allowReplacementInto(table.getParameters())) {
                // If the target table exists and is newer or same as current update based on repl.last.id, then just noop it.
                return tracker;
            }
        }
        if (tableDesc.getLocation() == null) {
            tableDesc.setLocation(location(tableDesc, parentDb));
        }
        /* Note: In the following section, Metadata-only import handling logic is
     interleaved with regular repl-import logic. The rule of thumb being
     followed here is that MD-only imports are essentially ALTERs. They do
     not load data, and should not be "creating" any metadata - they should
     be replacing instead. The only place it makes sense for a MD-only import
     to create is in the case of a table that's been dropped and recreated,
     or in the case of an unpartitioned table. In all other cases, it should
     behave like a noop or a pure MD alter.
  */
        if (table == null) {
            newTableTasks(tableDesc);
        } else {
            existingTableTasks(tableDesc, table, replicationSpec);
        }
        if (!isPartitioned(tableDesc)) {
            createTableReplLogTask(tableDesc.getTableName(), tableDesc.tableType());
        }
        return tracker;
    } catch (Exception e) {
        throw new SemanticException(e);
    }
}
Also used : ReplicationSpec(org.apache.hadoop.hive.ql.parse.ReplicationSpec) Table(org.apache.hadoop.hive.ql.metadata.Table) ImportTableDesc(org.apache.hadoop.hive.ql.plan.ImportTableDesc) Database(org.apache.hadoop.hive.metastore.api.Database) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) IOException(java.io.IOException) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException)

Example 97 with SemanticException

use of org.apache.hadoop.hive.ql.parse.SemanticException in project hive by apache.

the class FSTableEvent method partitionDesc.

private AddPartitionDesc partitionDesc(Path fromPath, ImportTableDesc tblDesc, Partition partition) throws SemanticException {
    try {
        AddPartitionDesc partsDesc = new AddPartitionDesc(tblDesc.getDatabaseName(), tblDesc.getTableName(), EximUtil.makePartSpec(tblDesc.getPartCols(), partition.getValues()), partition.getSd().getLocation(), partition.getParameters());
        AddPartitionDesc.OnePartitionDesc partDesc = partsDesc.getPartition(0);
        partDesc.setInputFormat(partition.getSd().getInputFormat());
        partDesc.setOutputFormat(partition.getSd().getOutputFormat());
        partDesc.setNumBuckets(partition.getSd().getNumBuckets());
        partDesc.setCols(partition.getSd().getCols());
        partDesc.setSerializationLib(partition.getSd().getSerdeInfo().getSerializationLib());
        partDesc.setSerdeParams(partition.getSd().getSerdeInfo().getParameters());
        partDesc.setBucketCols(partition.getSd().getBucketCols());
        partDesc.setSortCols(partition.getSd().getSortCols());
        partDesc.setLocation(new Path(fromPath, Warehouse.makePartName(tblDesc.getPartCols(), partition.getValues())).toString());
        partsDesc.setReplicationSpec(metadata.getReplicationSpec());
        return partsDesc;
    } catch (Exception e) {
        throw new SemanticException(e);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) AddPartitionDesc(org.apache.hadoop.hive.ql.plan.AddPartitionDesc) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException)

Example 98 with SemanticException

use of org.apache.hadoop.hive.ql.parse.SemanticException in project hive by apache.

the class FSTableEvent method tableDesc.

@Override
public ImportTableDesc tableDesc(String dbName) throws SemanticException {
    try {
        Table table = new Table(metadata.getTable());
        ImportTableDesc tableDesc = new ImportTableDesc(StringUtils.isBlank(dbName) ? table.getDbName() : dbName, table);
        tableDesc.setReplicationSpec(metadata.getReplicationSpec());
        return tableDesc;
    } catch (Exception e) {
        throw new SemanticException(e);
    }
}
Also used : Table(org.apache.hadoop.hive.ql.metadata.Table) ImportTableDesc(org.apache.hadoop.hive.ql.plan.ImportTableDesc) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException)

Example 99 with SemanticException

use of org.apache.hadoop.hive.ql.parse.SemanticException in project hive by apache.

the class LoadConstraint method tasks.

public TaskTracker tasks() throws IOException, SemanticException {
    URI fromURI = EximUtil.getValidatedURI(context.hiveConf, stripQuotes(event.rootDir().toUri().toString()));
    Path fromPath = new Path(fromURI.getScheme(), fromURI.getAuthority(), fromURI.getPath());
    try {
        FileSystem fs = FileSystem.get(fromPath.toUri(), context.hiveConf);
        JSONObject json = new JSONObject(EximUtil.readAsString(fs, fromPath));
        String pksString = json.getString("pks");
        String fksString = json.getString("fks");
        String uksString = json.getString("uks");
        String nnsString = json.getString("nns");
        List<Task<? extends Serializable>> tasks = new ArrayList<Task<? extends Serializable>>();
        if (pksString != null && !pksString.isEmpty()) {
            AddPrimaryKeyHandler pkHandler = new AddPrimaryKeyHandler();
            DumpMetaData pkDumpMetaData = new DumpMetaData(fromPath, DumpType.EVENT_ADD_PRIMARYKEY, Long.MAX_VALUE, Long.MAX_VALUE, null, context.hiveConf);
            pkDumpMetaData.setPayload(pksString);
            tasks.addAll(pkHandler.handle(new MessageHandler.Context(dbNameToLoadIn, null, fromPath.toString(), null, pkDumpMetaData, context.hiveConf, context.hiveDb, null, LOG)));
        }
        if (uksString != null && !uksString.isEmpty()) {
            AddUniqueConstraintHandler ukHandler = new AddUniqueConstraintHandler();
            DumpMetaData ukDumpMetaData = new DumpMetaData(fromPath, DumpType.EVENT_ADD_UNIQUECONSTRAINT, Long.MAX_VALUE, Long.MAX_VALUE, null, context.hiveConf);
            ukDumpMetaData.setPayload(uksString);
            tasks.addAll(ukHandler.handle(new MessageHandler.Context(dbNameToLoadIn, null, fromPath.toString(), null, ukDumpMetaData, context.hiveConf, context.hiveDb, null, LOG)));
        }
        if (nnsString != null && !nnsString.isEmpty()) {
            AddNotNullConstraintHandler nnHandler = new AddNotNullConstraintHandler();
            DumpMetaData nnDumpMetaData = new DumpMetaData(fromPath, DumpType.EVENT_ADD_NOTNULLCONSTRAINT, Long.MAX_VALUE, Long.MAX_VALUE, null, context.hiveConf);
            nnDumpMetaData.setPayload(nnsString);
            tasks.addAll(nnHandler.handle(new MessageHandler.Context(dbNameToLoadIn, null, fromPath.toString(), null, nnDumpMetaData, context.hiveConf, context.hiveDb, null, LOG)));
        }
        if (fksString != null && !fksString.isEmpty()) {
            AddForeignKeyHandler fkHandler = new AddForeignKeyHandler();
            DumpMetaData fkDumpMetaData = new DumpMetaData(fromPath, DumpType.EVENT_ADD_FOREIGNKEY, Long.MAX_VALUE, Long.MAX_VALUE, null, context.hiveConf);
            fkDumpMetaData.setPayload(fksString);
            tasks.addAll(fkHandler.handle(new MessageHandler.Context(dbNameToLoadIn, null, fromPath.toString(), null, fkDumpMetaData, context.hiveConf, context.hiveDb, null, LOG)));
        }
        tasks.forEach(tracker::addTask);
        return tracker;
    } catch (Exception e) {
        throw new SemanticException(ErrorMsg.INVALID_PATH.getMsg(), e);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Context(org.apache.hadoop.hive.ql.exec.repl.bootstrap.load.util.Context) Task(org.apache.hadoop.hive.ql.exec.Task) Serializable(java.io.Serializable) AddPrimaryKeyHandler(org.apache.hadoop.hive.ql.parse.repl.load.message.AddPrimaryKeyHandler) AddForeignKeyHandler(org.apache.hadoop.hive.ql.parse.repl.load.message.AddForeignKeyHandler) DumpMetaData(org.apache.hadoop.hive.ql.parse.repl.load.DumpMetaData) ArrayList(java.util.ArrayList) AddNotNullConstraintHandler(org.apache.hadoop.hive.ql.parse.repl.load.message.AddNotNullConstraintHandler) URI(java.net.URI) IOException(java.io.IOException) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) JSONObject(org.json.JSONObject) FileSystem(org.apache.hadoop.fs.FileSystem) AddUniqueConstraintHandler(org.apache.hadoop.hive.ql.parse.repl.load.message.AddUniqueConstraintHandler) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException)

Example 100 with SemanticException

use of org.apache.hadoop.hive.ql.parse.SemanticException in project hive by apache.

the class LoadDatabase method tasks.

public TaskTracker tasks() throws SemanticException {
    try {
        Database dbInMetadata = readDbMetadata();
        Task<? extends Serializable> dbRootTask = existEmptyDb(dbInMetadata.getName()) ? alterDbTask(dbInMetadata, context.hiveConf) : createDbTask(dbInMetadata);
        dbRootTask.addDependentTask(setOwnerInfoTask(dbInMetadata));
        tracker.addTask(dbRootTask);
        return tracker;
    } catch (Exception e) {
        throw new SemanticException(e);
    }
}
Also used : Database(org.apache.hadoop.hive.metastore.api.Database) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException)

Aggregations

SemanticException (org.apache.hadoop.hive.ql.parse.SemanticException)131 ArrayList (java.util.ArrayList)64 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)36 HashMap (java.util.HashMap)30 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)27 Path (org.apache.hadoop.fs.Path)22 IOException (java.io.IOException)20 LinkedHashMap (java.util.LinkedHashMap)19 List (java.util.List)18 TableScanOperator (org.apache.hadoop.hive.ql.exec.TableScanOperator)18 Node (org.apache.hadoop.hive.ql.lib.Node)17 ExprNodeGenericFuncDesc (org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc)17 ReduceSinkOperator (org.apache.hadoop.hive.ql.exec.ReduceSinkOperator)16 DefaultRuleDispatcher (org.apache.hadoop.hive.ql.lib.DefaultRuleDispatcher)16 Dispatcher (org.apache.hadoop.hive.ql.lib.Dispatcher)16 GraphWalker (org.apache.hadoop.hive.ql.lib.GraphWalker)16 ExprNodeColumnDesc (org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc)16 Operator (org.apache.hadoop.hive.ql.exec.Operator)15 DefaultGraphWalker (org.apache.hadoop.hive.ql.lib.DefaultGraphWalker)15 Table (org.apache.hadoop.hive.ql.metadata.Table)14