hive元存储问题

ohfgkhjo  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(337)

我正在尝试使用配置单元JavaAPI更新配置单元表分区this:-
1.正在提取不在metastore中的分区。
2.将这些分区添加到表中。
3.返回hive命令行,运行show partitions和msck repair table命令,确保一切正常。
我做了什么got:-
1.显示分区工作正常(给出我添加的分区列表)。
2.msck repair命令不起作用(获取以下信息:metastore中不存在分区。)
下面是我正在使用的一段代码:-

public class HiveMetastoreChecker {

public static void main(String[] args) {
    final String dbName = "db_name";
    final String tableName = "db_name.table_name";

    CheckResult result = new CheckResult();
    try {
        Configuration configuration = new Configuration();
        HiveConf conf = new HiveConf();
        conf.addResource(configuration);
        Hive hive = Hive.get(conf, true);
        HiveMetaStoreChecker checker = new HiveMetaStoreChecker(hive);

        Table table = new Table(dbName, tableName);

        table.setDbName(dbName);
        table.setInputFormatClass(TextInputFormat.class);
        table.setOutputFormatClass(HiveIgnoreKeyTextOutputFormat.class);

        table = hive.getTable(dbName, tableName);

        checker.checkMetastore(dbName, tableName, null, result);
        System.out.println(table.getDataLocation());
        List<CheckResult.PartitionResult> partitionNotInMs = result.getPartitionsNotInMs();
        System.out.println("not in ms " + partitionNotInMs.size());
        List<org.apache.hadoop.hive.ql.metadata.Partition> partitions = hive.getPartitions(table);

        System.out.println("partitions size " + partitions.size());
        AddPartitionDesc apd = new AddPartitionDesc(table.getDbName(), table.getTableName(), false);

        List<String> finalListOfPartitionsNotInMs = new ArrayList<String>();
        for (CheckResult.PartitionResult part : partitionNotInMs){
            if(!finalListOfPartitionsNotInMs.contains(part.getPartitionName().replace("/",""))){
                finalListOfPartitionsNotInMs.add(part.getPartitionName().replace("/",""));
            }
        }

        for (String partition:finalListOfPartitionsNotInMs) {

            apd.addPartition(Warehouse.makeSpecFromName(partition), table.getDataLocation().toString());
        }
       hive.createPartitions(apd);
    } catch (HiveException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (MetaException e) {
        e.printStackTrace();
    }
}

}
任何帮助都将不胜感激。
谢谢。

sxpgvts3

sxpgvts31#

配置单元上的msck修复失败?如果是,则检查分区列名是否为大写字母。我发现了同样的问题,我在awss3上的分区类似于dca=1000。
如果是这样的话,那么使用sparksql执行msck repair,它就会正常工作,以防您不想将分区重命名为小写。

相关问题