/** * Get the name of the dataset from the URI * * @param uri The dataset or view URI * @return The dataset name */ private static String uriToName(URI uri) { return Registration.lookupDatasetUri(URI.create( uri.getRawSchemeSpecificPart())).second().get("dataset"); }
static void finishMove(FileSystem fs, List<Pair<Path, Path>> staged) { try { for (Pair<Path, Path> pair : staged) { if (!fs.rename(pair.first(), pair.second())) { throw new IOException( "Failed to rename " + pair.first() + " to " + pair.second()); } } } catch (IOException e) { throw new DatasetIOException("Could not finish replacement", e); } }
public Pair<String, Class<? extends Comparable>> merge( Pair<String, Class<? extends Comparable>> left, Pair<String, Class<? extends Comparable>> right) { String name = left.first(); if (name == null || name.isEmpty()) { name = right.first(); } if (left.second() == String.class) { return new Pair<String, Class<? extends Comparable>>(name, String.class); } else if (right.second() == String.class) { return new Pair<String, Class<? extends Comparable>>(name, String.class); } else if (left.second() == Long.class) { return new Pair<String, Class<? extends Comparable>>(name, Long.class); } else if (right.second() == Long.class) { return new Pair<String, Class<? extends Comparable>>(name, Long.class); } return new Pair<String, Class<? extends Comparable>>(name, Integer.class); }
current = addProjected(projected, fp.getName(), current); } else if (projected instanceof Range) { compatible.add(Pair.of(fp.getName(), (Range) projected)); } else if (compatible.size() == 1) { Pair<String, Range> pair = compatible.get(0); return addProjected((Predicate<?>) pair.second(), pair.first(), current); } else { return new RangeGroupIterator(constraint, compatible, current);
@SuppressWarnings("unchecked") public static <R extends DatasetRepository> R open(URI uri) { return (R) lookupRepoUri(uri).first(); }
public static Pair<URIPattern, Map<String, String>> lookupDatasetPattern(URI uri) { for (URIPattern pattern : DATASET_PATTERNS.keySet()) { Map<String, String> match = pattern.getMatch(uri); if (match != null) { return Pair.of(pattern, match); } } throw new IllegalArgumentException("Unknown dataset URI pattern: dataset:" + uri); }
public static <T, U> Pair<T, U> of(T first, U second) { return new Pair<T, U>(first, second); }
/** * Load a {@link DatasetRepository} for the given dataset, view or repository URI. * <p> * URI formats are defined by {@code Dataset} implementations, but must begin * with "dataset:" or "view:". * * @param uri a {@code Dataset} or {@code View} URI. * @param <R> The type of {@code DatasetRepository} expected. * @return a {@code DatasetRepository} responsible for the given URI. */ @SuppressWarnings("unchecked") public static <R extends DatasetRepository> R repositoryFor(URI uri) { boolean isRepoUri = URIBuilder.REPO_SCHEME.equals(uri.getScheme()); Preconditions.checkArgument(isRepoUri || URIBuilder.DATASET_SCHEME.equals(uri.getScheme()) || URIBuilder.VIEW_SCHEME.equals(uri.getScheme()), "Not a repository, dataset, or view URI: " + uri); Pair<DatasetRepository, Map<String, String>> pair; if (URIBuilder.REPO_SCHEME.equals(uri.getScheme())) { pair = Registration.lookupRepoUri( URI.create(uri.getRawSchemeSpecificPart())); } else { pair = Registration.lookupDatasetUri( URI.create(uri.getRawSchemeSpecificPart())); } return (R) pair.first(); }
public static Pair<URIPattern, Map<String, String>> lookupPatternByRepoUri(URI uri) { for (URIPattern pattern : REPO_TO_DATASET_PATTERNS.keySet()) { Map<String, String> match = pattern.getMatch(uri); if (match != null) { URIPattern datasetPattern = REPO_TO_DATASET_PATTERNS.get(pattern); return Pair.of(datasetPattern, match); } } throw new IllegalArgumentException("Unknown repository URI pattern: dataset:" + uri); }
new Pair<String, Class<? extends Comparable>>(name, dataClass(value)));
private static boolean deleteWithTrash(URI uri, boolean useTrash){ Preconditions.checkArgument( URIBuilder.DATASET_SCHEME.equals(uri.getScheme()), "Not a dataset URI: " + uri); Pair<DatasetRepository, Map<String, String>> pair = Registration.lookupDatasetUri(URI.create(uri.getRawSchemeSpecificPart())); DatasetRepository repo = pair.first(); Map<String, String> uriOptions = pair.second(); return useTrash ? repo.moveToTrash(uriOptions.get(URIBuilder.NAMESPACE_OPTION), uriOptions.get(URIBuilder.DATASET_NAME_OPTION)) : repo.delete(uriOptions.get(URIBuilder.NAMESPACE_OPTION), uriOptions.get(URIBuilder.DATASET_NAME_OPTION)); }
private static String uriToName(URI uri) { return Registration.lookupDatasetUri(URI.create( uri.getRawSchemeSpecificPart())).second().get("dataset"); } }
public static TimeDomain get(PartitionStrategy strategy, String source) { return domains.getUnchecked(Pair.of(strategy, source)); }
/** * Constructs a builder based on the given dataset or view URI. * * @param uri a dataset or view URI * * @since 0.17.0 */ public URIBuilder(URI uri) { Preconditions.checkNotNull(uri, "URI cannot be null"); boolean isViewUri = VIEW_SCHEME.equals(uri.getScheme()); Preconditions.checkArgument(isViewUri || DATASET_SCHEME.equals(uri.getScheme()), "Not a dataset or view URI: " + uri); Pair<URIPattern, Map<String, String>> pair = Registration .lookupDatasetPattern(URI.create(uri.getRawSchemeSpecificPart())); this.pattern = pair.first(); this.isView = isViewUri; options.put(NAMESPACE_OPTION, NAMESPACE_DEFAULT); options.putAll(pair.second()); }
/** * Get the name of the dataset from the URI * * @param uri The dataset or view URI * @return The dataset name */ private static String uriToName(URI uri) { return Registration.lookupDatasetUri(URI.create( uri.getRawSchemeSpecificPart())).second().get("dataset"); }
public static Pair<DatasetRepository, Map<String, String>> lookupRepoUri(URI repoUri) { for (URIPattern pattern : REPO_PATTERNS.keySet()) { Map<String, String> match = pattern.getMatch(repoUri); if (match != null) { return Pair.of(REPO_PATTERNS.get(pattern).getFromOptions(match), match); } } throw new IllegalArgumentException("Unknown repository URI pattern: repo:" + repoUri); }
@Override public MarkerRange.Builder update( MarkerRange.Builder current, Range range) { if (range.hasLowerBound()) { for (Pair<String, Range> pair : fields) { current.addToStart(pair.first(), pair.second().lowerEndpoint()); } } if (range.hasUpperBound()) { for (Pair<String, Range> pair : fields) { current.addToEnd(pair.first(), pair.second().upperEndpoint()); } } return current; } }
protected static Map<String, String> optionsForUri(URI uri) { Preconditions.checkArgument(isDatasetOrViewUri(uri.toString()), "Must be a dataset or view URI: " + uri); return Registration.lookupDatasetUri( URI.create(uri.getSchemeSpecificPart())).second(); }
static List<Pair<Path, Path>> stageMove(FileSystem fs, Path src, Path dest, String ext) { List<Pair<Path, Path>> staged; try { // make sure the destination exists if (!fs.exists(dest)) { fs.mkdirs(dest); } FileStatus[] stats = fs.listStatus(src); staged = Lists.newArrayList(); for (FileStatus stat : stats) { if (stat.isDir()) { continue; } Path srcFile = stat.getPath(); Path dotFile = new Path(dest, "." + srcFile.getName() + "." + ext); Path destFile = new Path(dest, srcFile.getName()); if (fs.rename(srcFile, dotFile)) { staged.add(Pair.of(dotFile, destFile)); } else { throw new IOException( "Failed to rename " + srcFile + " to " + dotFile); } } } catch (IOException e) { throw new DatasetIOException( "Could not move contents of " + src + " to " + dest, e); } return staged; }