/** * Construct a new {@link DateFormatPartitioner} for Universal Coordinated * Time, UTC (+00:00). * @param sourceName Source field name (the field should be a long) * @param name Partition name * @param format A String format for the {@link SimpleDateFormat} constructor * @param cardinality * A cardinality hint for the number of partitions that will be * created by this partitioner. For example, "MM-dd" produces about * 365 partitions per year. */ public DateFormatPartitioner(String sourceName, String name, String format, int cardinality, TimeZone zone) { super(sourceName, name, Long.class, String.class, cardinality); Preconditions.checkArgument(CharMatcher.is('/').matchesNoneOf(format), "Illegal format: \"/\" is not allowed (use multiple partition fields)"); this.format = new SimpleDateFormat(format); this.format.setTimeZone(zone); }
private static boolean addSimpleMatch( String pattern, String part, Map<String, String> storage) { if (VAR_START.matches(pattern.charAt(0))) { storage.put(pattern.substring(1), part); return true; } else { // not a captured part, verify it matches the pattern return pattern.equals(part); } }
@VisibleForTesting static String sample(@Nullable String value) { if (value != null) { return NON_PRINTABLE.replaceFrom( value.subSequence(0, min(50, value.length())), '.'); } else { return "null"; } }
private static void addAuthority(URI uri, Map<String, String> storage) { if (uri.getHost() != null) { storage.put(HOST, uri.getHost()); } if (uri.getPort() >= 0) { storage.put(PORT, String.valueOf(uri.getPort())); } final String userInfo = uri.getUserInfo(); if (userInfo != null) { // the first colon is the delimiter between the username and the password int index = USER_PASS_SEPARATOR.indexIn(userInfo); if (index > 0) { storage.put(USERNAME, userInfo.substring(0, index)); storage.put(PASSWORD, userInfo.substring(index+1)); } else { storage.put(USERNAME, userInfo); } } }
private static String constructPath(Map<String, String> match, String pattern) { LinkedList<String> patternParts = Lists.newLinkedList( PATH_SPLITTER.split(pattern)); List<String> pathParts = Lists .newArrayListWithExpectedSize(patternParts.size()); for (String part : patternParts) { if (!part.isEmpty()) { // only supports simple matches, like matching if (VAR_START.matches(part.charAt(0))) { String name = part.substring(1); if (match.containsKey(name)) { pathParts.add(match.remove(name)); } else if (!part.startsWith("*")) { // required variable is missing throw new IllegalArgumentException( "Missing required option: " + name); } } else { // it is a required URI part pathParts.add(part); } } else { // preserve additional slashes in paths pathParts.add(part); } } return PATH_JOINER.join(pathParts); }