private boolean createLocationForAddedPartition()

in metacat-connector-hive/src/main/java/com/netflix/metacat/connector/hive/metastore/MetacatHMSHandler.java [371:419]


    private boolean createLocationForAddedPartition(
            final Table tbl, final Partition part) throws MetaException {
        Path partLocation = null;
        String partLocationStr = null;
        if (part.getSd() != null) {
            partLocationStr = part.getSd().getLocation();
        }

        if (partLocationStr == null || partLocationStr.isEmpty()) {
            // set default location if not specified and this is
            // a physical table partition (not a view)
            if (tbl.getSd().getLocation() != null) {
                partLocation = new Path(tbl.getSd().getLocation(), Warehouse
                        .makePartName(tbl.getPartitionKeys(), part.getValues()));
            }
        } else {
            if (tbl.getSd().getLocation() == null) {
                throw new MetaException("Cannot specify location for a view partition");
            }
            partLocation = getWh().getDnsPath(new Path(partLocationStr));
        }

        boolean result = false;
        if (partLocation != null) {
            part.getSd().setLocation(partLocation.toString());
            final boolean doFileSystemCalls = getHiveConf().getBoolean("hive.metastore.use.fs.calls", true)
                || (tbl.getParameters() != null && Boolean.parseBoolean(tbl.getParameters()
                .getOrDefault("hive.metastore.use.fs.calls", "false")));
            if (doFileSystemCalls) {
                // Check to see if the directory already exists before calling
                // mkdirs() because if the file system is read-only, mkdirs will
                // throw an exception even if the directory already exists.
                if (!getWh().isDir(partLocation)) {
                    //
                    // Added to track the number of partition locations that do not exist before
                    // adding the partition metadata
                    registry.counter(HiveMetrics.CounterHivePartitionPathIsNotDir.getMetricName(),
                        "database", tbl.getDbName(), "table", tbl.getTableName()).increment();
                    logInfo(String.format("Partition location %s does not exist for table %s",
                        partLocation, tbl.getTableName()));
                    if (!getWh().mkdirs(partLocation, true)) {
                        throw new MetaException(partLocation + " is not a directory or unable to create one");
                    }
                }
                result = true;
            }
        }
        return result;
    }