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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations