private void handleLineage(Table destinationTable, LoadTableDesc ltd, Operator output)
      throws SemanticException {
    if (ltd != null) {
      queryState.getLineageState().mapDirToOp(ltd.getSourcePath(), output);
    }
    if (HiveOperation.CREATETABLE_AS_SELECT.equals(queryState.getHiveOperation())) {

      Path tlocation = null;
      String tName = Utilities.getDbTableName(tableDesc.getDbTableName())[1];
      try {
        String suffix = Utilities.getTableOrMVSuffix(ctx,
                AcidUtils.isTableSoftDeleteEnabled(destinationTable, conf));
        Warehouse wh = new Warehouse(conf);
        tlocation = wh.getDefaultTablePath(db.getDatabase(tableDesc.getDatabaseName()),
            tName + suffix, tableDesc.isExternal());

        if (destinationTable != null && destinationTable.getSd() != null
                && destinationTable.getPath() != null) {
          tlocation = destinationTable.getPath();
        }
      } catch (MetaException|HiveException e) {
        throw new SemanticException(e);
      }

      queryState.getLineageState()
          .mapDirToOp(tlocation, output);
    } else if (HiveOperation.CREATE_MATERIALIZED_VIEW.equals(queryState.getHiveOperation())) {
      Path tlocation;
      String [] dbTable = Utilities.getDbTableName(createVwDesc.getViewName());
      try {
        Warehouse wh = new Warehouse(conf);
        Map<String, String> tblProps = createVwDesc.getTblProps();
        tlocation = wh.getDefaultTablePath(db.getDatabase(dbTable[0]), dbTable[1],
          tblProps == null || !AcidUtils.isTablePropertyTransactional(tblProps));
      } catch (MetaException|HiveException e) {
        throw new SemanticException(e);
      }

      queryState.getLineageState()
        .mapDirToOp(tlocation, output);
    }
  }
We will directly insert to the final destination in the following cases:
1. Non native table
2. Micro-managed (insert only table)
3. Full ACID table and operation type is INSERT
ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java