public static RelOptMaterialization createCTEMaterialization(String viewName, RelNode body, HiveConf conf) {
    RelOptCluster cluster = body.getCluster();
    List<ColumnInfo> columns = new ArrayList<>();
    for (RelDataTypeField f : body.getRowType().getFieldList()) {
      TypeInfo info = TypeConverter.convert(f.getType());
      columns.add(new ColumnInfo(f.getName(), info, f.getType().isNullable(), viewName, false, false));
    }
    List<String> fullName = Arrays.asList("cte", viewName);
    org.apache.hadoop.hive.metastore.api.Table metaTable = Table.getEmptyTable("cte", viewName);
    metaTable.setTemporary(true);
    try {
      // Setting a location avoids a NPE when fetching statistics
      metaTable.getSd().setLocation(SessionState.generateTempTableLocation(conf));
    } catch (MetaException e) {
      throw new CalciteCteException("Failed to create temporary location", e);
    }
    Table hiveTable = new Table(metaTable);
    hiveTable.setMaterializedTable(true);
    RelOptHiveTable optTable =
        new RelOptHiveTable(null, cluster.getTypeFactory(), fullName, body.getRowType(), hiveTable, columns,
            Collections.emptyList(), Collections.emptyList(), new HiveConf(), new QueryTables(true), new HashMap<>(),
            new HashMap<>(), new AtomicInteger());
    optTable.setRowCount(cluster.getMetadataQuery().getRowCount(body));
    final TableScan scan =
        new HiveTableScan(cluster, cluster.traitSetOf(HiveRelNode.CONVENTION), optTable, viewName, null, false, false);

    return new RelOptMaterialization(scan, body, null, fullName);
  }
Validate if given materialized view has SELECT privileges for current user
@param cachedMVTableList
@return false if user does not have privilege otherwise true
@throws HiveException
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/views/HiveMaterializedViewUtils.java