static Task<ExportWork> analyzeExport(ASTNode ast, @Nullable String acidTableName, Hive db,
      HiveConf conf, Set<ReadEntity> inputs, Set<WriteEntity> outputs) throws SemanticException {
    Tree tableTree = ast.getChild(0);
    Tree toTree = ast.getChild(1);

    ReplicationSpec replicationSpec;
    if (ast.getChildCount() > 2) {
      // Replication case: export table <tbl> to <location> for replication
      replicationSpec = new ReplicationSpec((ASTNode) ast.getChild(2));
    } else {
      // Export case
      replicationSpec = new ReplicationSpec();
    }
    if (replicationSpec.getCurrentReplicationState() == null) {
      try {
        long currentEventId = db.getMSC().getCurrentNotificationEventId().getEventId();
        replicationSpec.setCurrentReplicationState(String.valueOf(currentEventId));
      } catch (Exception e) {
        throw new SemanticException("Error when getting current notification event ID", e);
      }
    }

    // initialize source table/partition
    TableSpec ts;

    try {
      ts = new TableSpec(db, conf, (ASTNode) tableTree, false, true);
    } catch (SemanticException sme) {
      if (!replicationSpec.isInReplicationScope()) throw sme;
      if ((sme.getCause() instanceof InvalidTableException)
            || (sme instanceof Table.ValidationFailureSemanticException)) {
        // If we're in replication scope, it's possible that we're running the export long after
        // the table was dropped, so the table not existing currently or being a different kind of
        // table is not an error - it simply means we should no-op, and let a future export
        // capture the appropriate state
        ts = null;
      } else {
        throw sme;
      }
    }

    if (ts != null && (ts.tableHandle.isView() || ts.tableHandle.isMaterializedView())) {
      throw new SemanticException("Views and Materialized Views can not be exported.");
    }

    // initialize export path
    String tmpPath = stripQuotes(toTree.getText());
    // All parsing is done, we're now good to start the export process
    TableExport.Paths exportPaths =
        new TableExport.Paths(ASTErrorUtils.getMsg(
            ErrorMsg.INVALID_PATH.getMsg(), ast), tmpPath, conf, false);
    // Note: this tableExport is actually never used other than for auth, and another one is
    //       created when the task is executed. So, we don't care about the correct MM state here.
    TableExport.AuthEntities authEntities = new TableExport(
        exportPaths, ts, replicationSpec, db, null, conf, null).getAuthEntities();
    inputs.addAll(authEntities.inputs);
    outputs.addAll(authEntities.outputs);
    String exportRootDirName = tmpPath;
    MmContext mmCtx = MmContext.createIfNeeded(ts == null ? null : ts.tableHandle);

    Utilities.FILE_OP_LOGGER.debug("Exporting table {}: MM context {}",
        ts == null ? null : ts.getTableName(), mmCtx);
      // Configure export work
    ExportWork exportWork = new ExportWork(exportRootDirName, ts, replicationSpec,
        ASTErrorUtils.getMsg(ErrorMsg.INVALID_PATH.getMsg(), ast), acidTableName, mmCtx);
    // Create an export task and add it as a root task
    return TaskFactory.get(exportWork);
  }
@param acidTableName - table name in db.table format; not NULL if exporting Acid table
ql/src/java/org/apache/hadoop/hive/ql/parse/ExportSemanticAnalyzer.java