Code review comment: `getCurrentInternalCatalog` only return `InternalCatalog`, no matter what is your current catalog is. But `getCurrentCatalog` will return the real current catalog(set by `switch` cmd)

Code before review:
private void analyzeTargetTable(Analyzer analyzer) throws AnalysisException {
if (targetTable == null) {
DatabaseIf db = analyzer.getEnv().getCurrentCatalog().getDbOrAnalysisException(tblName.getDb());
if (db instanceof Database) {
targetTable = (Table) db.getTableOrAnalysisException(tblName.getTbl());
} else if (db instanceof JdbcExternalDatabase) {
JdbcExternalTable jdbcTable = (JdbcExternalTable) db.getTableOrAnalysisException(tblName.getTbl());
targetTable = jdbcTable.getJdbcTable();
} else {
throw new AnalysisException("Un support insert target table");
}
}
if (targetTable instanceof OlapTable) {
OlapTable olapTable = (OlapTable) targetTable;
if (targetPartitionNames != null) {
targetPartitionIds = Lists.newArrayList();
if (olapTable.getPartitionInfo().getType() == PartitionType.UNPARTITIONED) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_PARTITION_CLAUSE_NO_ALLOWED);
}
for (String partName : targetPartitionNames.getPartitionNames()) {
Partition part = olapTable.getPartition(partName, targetPartitionNames.isTemp());
if (part == null) {
ErrorReport.reportAnalysisException(
ErrorCode.ERR_UNKNOWN_PARTITION, partName, targetTable.getName());
}
targetPartitionIds.add(part.getId());
}
}
DescriptorTable descTable = analyzer.getDescTbl();
olapTuple = descTable.createTupleDescriptor();
for (Column col : olapTable.getFullSchema()) {
SlotDescriptor slotDesc = descTable.addSlotDescriptor(olapTuple);
slotDesc.setIsMaterialized(true);
slotDesc.setType(col.getType());
slotDesc.setColumn(col);
slotDesc.setIsNullable(col.isAllowNull());
}
indexIdToSchemaHash = olapTable.getIndexIdToSchemaHash();
} else if (targetTable instanceof MysqlTable || targetTable instanceof OdbcTable
|| targetTable instanceof JdbcTable) {
if (targetPartitionNames != null) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_PARTITION_CLAUSE_NO_ALLOWED);
}
} else if (targetTable instanceof BrokerTable) {
if (targetPartitionNames != null) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_PARTITION_CLAUSE_NO_ALLOWED);
}
BrokerTable brokerTable = (BrokerTable) targetTable;
if (!brokerTable.isWritable()) {
throw new AnalysisException("table " + brokerTable.getName()
+ "is not writable. path should be an dir");
}
} else {
ErrorReport.reportAnalysisException(
ErrorCode.ERR_NON_INSERTABLE_TABLE, targetTable.getName(), targetTable.getType());
}
}

Line under review: DatabaseIf db = analyzer.getEnv().getCurrentCatalog().getDbOrAnalysisException(tblName.getDb());

Code after addressing the review:
private void analyzeTargetTable(Analyzer analyzer) throws AnalysisException {
if (targetTable == null) {
DatabaseIf db = analyzer.getEnv().getCatalogMgr()
.getCatalog(tblName.getCtl()).getDbOrAnalysisException(tblName.getDb());
if (db instanceof Database) {
targetTable = (Table) db.getTableOrAnalysisException(tblName.getTbl());
} else if (db instanceof JdbcExternalDatabase) {
JdbcExternalTable jdbcTable = (JdbcExternalTable) db.getTableOrAnalysisException(tblName.getTbl());
targetTable = jdbcTable.getJdbcTable();
} else {
throw new AnalysisException("Not support insert target table.");
}
}
if (targetTable instanceof OlapTable) {
OlapTable olapTable = (OlapTable) targetTable;
if (targetPartitionNames != null) {
targetPartitionIds = Lists.newArrayList();
if (olapTable.getPartitionInfo().getType() == PartitionType.UNPARTITIONED) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_PARTITION_CLAUSE_NO_ALLOWED);
}
for (String partName : targetPartitionNames.getPartitionNames()) {
Partition part = olapTable.getPartition(partName, targetPartitionNames.isTemp());
if (part == null) {
ErrorReport.reportAnalysisException(
ErrorCode.ERR_UNKNOWN_PARTITION, partName, targetTable.getName());
}
targetPartitionIds.add(part.getId());
}
}
DescriptorTable descTable = analyzer.getDescTbl();
olapTuple = descTable.createTupleDescriptor();
for (Column col : olapTable.getFullSchema()) {
SlotDescriptor slotDesc = descTable.addSlotDescriptor(olapTuple);
slotDesc.setIsMaterialized(true);
slotDesc.setType(col.getType());
slotDesc.setColumn(col);
slotDesc.setIsNullable(col.isAllowNull());
}
indexIdToSchemaHash = olapTable.getIndexIdToSchemaHash();
} else if (targetTable instanceof MysqlTable || targetTable instanceof OdbcTable
|| targetTable instanceof JdbcTable) {
if (targetPartitionNames != null) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_PARTITION_CLAUSE_NO_ALLOWED);
}
} else if (targetTable instanceof BrokerTable) {
if (targetPartitionNames != null) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_PARTITION_CLAUSE_NO_ALLOWED);
}
BrokerTable brokerTable = (BrokerTable) targetTable;
if (!brokerTable.isWritable()) {
throw new AnalysisException("table " + brokerTable.getName()
+ "is not writable. path should be an dir");
}
} else {
ErrorReport.reportAnalysisException(
ErrorCode.ERR_NON_INSERTABLE_TABLE, targetTable.getName(), targetTable.getType());
}
}