public static void updateTableStatsForCreateTable(Warehouse wh, Database db, Table tbl,
      EnvironmentContext envContext, Configuration conf, Path tblPath, boolean newDir)
      throws MetaException {
    // If the created table is a view, skip generating the stats
    if (MetaStoreUtils.isView(tbl)) {
      return;
    }
    assert tblPath != null;
    if (tbl.isSetDictionary() && tbl.getDictionary().getValues() != null) {
      List<ByteBuffer> values = tbl.getDictionary().getValues().
          remove(StatsSetupConst.STATS_FOR_CREATE_TABLE);
      ByteBuffer buffer;
      if (values != null && values.size() > 0 && (buffer = values.get(0)).hasArray()) {
        String val = new String(buffer.array(), StandardCharsets.UTF_8);
        StatsSetupConst.ColumnStatsSetup statsSetup = StatsSetupConst.ColumnStatsSetup.parseStatsSetup(val);
        if (statsSetup.enabled) {
          try {
            // For an Iceberg table, a new snapshot is generated, so any leftover files would be ignored
            // Set the column stats true in order to make it merge-able
            if (newDir || statsSetup.isIcebergTable ||
                wh.isEmptyDir(tblPath, FileUtils.HIDDEN_FILES_PATH_FILTER)) {
              List<String> columns = statsSetup.columnNames;
              if (columns == null || columns.isEmpty()) {
                columns = getColumnNames(tbl.getSd().getCols());
              }
              StatsSetupConst.setStatsStateForCreateTable(tbl.getParameters(), columns, StatsSetupConst.TRUE);
            }
          } catch (IOException e) {
            LOG.error("Error while checking the table directory: " + tblPath, e);
            throw ExceptionHandler.newMetaException(e);
          }
        }
      }
    }

    if (MetastoreConf.getBoolVar(conf, MetastoreConf.ConfVars.STATS_AUTO_GATHER) && 
            !getBooleanEnvProp(envContext, StatsSetupConst.DO_NOT_UPDATE_STATS)) {
      LOG.debug("Calling updateTableStatsSlow for table {}.{}.{}", tbl.getCatName(), tbl.getDbName(), tbl.getTableName());
      updateTableStatsSlow(db, tbl, wh, newDir, false, envContext);
    }
  }
@Test
  public void testUpdateTableStatsForCreateTableDoesNotInvokeStatsCalc() throws TException {
    // DO_NOT_UPDATE_STATS in env context is set to true => doesn't invoke stats calculation
    Map<String, String> params = new HashMap<>(paramsWithStats);
    Warehouse wh = mock(Warehouse.class);

    Table tbl = new TableBuilder()
            .setDbName(DB_NAME)
            .setTableName(TABLE_NAME)
            .addCol("id", "int")
            .setTableParams(params)
            .build(null);     

    EnvironmentContext env = new EnvironmentContext();
    env.putToProperties(StatsSetupConst.DO_NOT_UPDATE_STATS, StatsSetupConst.TRUE);

    MetaStoreServerUtils.updateTableStatsForCreateTable(wh, db, tbl, env,
            MetastoreConf.newMetastoreConf(), new Path("/tmp/0"), false);

    assertFalse(messageWasLogged(MessageFormat.format(
            STATS_CALC_CALL_LOG_MSG_FORMAT, tbl.getCatName(), tbl.getDbName(), tbl.getTableName())));
  }