public static boolean isBlank(String str) { return Strings.nullToEmpty(str).trim().isEmpty(); }
private static String trimEmptyToNull(String value) { return emptyToNull(nullToEmpty(value).trim()); }
public PrestoNode(String nodeIdentifier, URI httpUri, NodeVersion nodeVersion, boolean coordinator) { nodeIdentifier = emptyToNull(nullToEmpty(nodeIdentifier).trim()); this.nodeIdentifier = requireNonNull(nodeIdentifier, "nodeIdentifier is null or empty"); this.httpUri = requireNonNull(httpUri, "httpUri is null"); this.nodeVersion = requireNonNull(nodeVersion, "nodeVersion is null"); this.coordinator = coordinator; }
public static Set<String> parseClientTags(String clientTagsString) { Splitter splitter = Splitter.on(',').trimResults().omitEmptyStrings(); return ImmutableSet.copyOf(splitter.split(nullToEmpty(clientTagsString))); }
private Set<String> parseClientTags(HttpServletRequest servletRequest) { Splitter splitter = Splitter.on(',').trimResults().omitEmptyStrings(); return ImmutableSet.copyOf(splitter.split(nullToEmpty(servletRequest.getHeader(PRESTO_CLIENT_TAGS)))); }
public static Optional<String> defaultCredentialCachePath() { String value = nullToEmpty(System.getenv("KRB5CCNAME")); if (value.startsWith(FILE_PREFIX)) { value = value.substring(FILE_PREFIX.length()); } return Optional.ofNullable(emptyToNull(value)); } }
private Set<String> parseClientCapabilities(HttpServletRequest servletRequest) { Splitter splitter = Splitter.on(',').trimResults().omitEmptyStrings(); return ImmutableSet.copyOf(splitter.split(nullToEmpty(servletRequest.getHeader(PRESTO_CLIENT_CAPABILITIES)))); }
public static String keyFromPath(Path path) { checkArgument(path.isAbsolute(), "Path is not absolute: %s", path); String key = nullToEmpty(path.toUri().getPath()); if (key.startsWith(PATH_SEPARATOR)) { key = key.substring(PATH_SEPARATOR.length()); } if (key.endsWith(PATH_SEPARATOR)) { key = key.substring(0, key.length() - PATH_SEPARATOR.length()); } return key; }
private static void assertExceptionMessage(String sql, Exception exception, @Language("RegExp") String regex) { if (!nullToEmpty(exception.getMessage()).matches(regex)) { fail(format("Expected exception message '%s' to match '%s' for query: %s", exception.getMessage(), regex, sql), exception); } }
private static void assertExceptionMessage(String sql, Exception exception, @Language("RegExp") String regex) { if (!nullToEmpty(exception.getMessage()).matches(regex)) { fail(format("Expected exception message '%s' to match '%s' for query: %s", exception.getMessage(), regex, sql), exception); } }
@Nullable public static String nullToEmptyIfNeeded(@Nullable String value) { //CHECKSTYLE.OFF: Regexp return replaceWithDefault() ? Strings.nullToEmpty(value) : value; //CHECKSTYLE.ON: Regexp }
private static Slice slice(@Nullable String s) { return utf8Slice(nullToEmpty(s)); }
private static boolean isPrestoQueryInvalid(SQLException e) { for (Throwable t = e.getCause(); t != null; t = t.getCause()) { if (t.toString().contains(".SemanticException:")) { return true; } if (t.toString().contains(".ParsingException:")) { return true; } if (nullToEmpty(t.getMessage()).matches("Function .* not registered")) { return true; } } return false; }
private String dumpConfiguration(final Map<String, String> configMap) { final StringBuilder sb = new StringBuilder(); sb.append("# Configuration of graylog2-").append(commandName).append(" ").append(version).append(System.lineSeparator()); sb.append("# Generated on ").append(Tools.nowUTC()).append(System.lineSeparator()); for (Map.Entry<String, String> entry : configMap.entrySet()) { sb.append(entry.getKey()).append('=').append(nullToEmpty(entry.getValue())).append(System.lineSeparator()); } return sb.toString(); }
private static Set<String> possibleIdentifiers() { ImmutableSet.Builder<String> names = ImmutableSet.builder(); Vocabulary vocabulary = SqlBaseLexer.VOCABULARY; for (int i = 0; i <= vocabulary.getMaxTokenType(); i++) { String name = nullToEmpty(vocabulary.getLiteralName(i)); Matcher matcher = IDENTIFIER.matcher(name); if (matcher.matches()) { names.add(matcher.group(1)); } } return names.build(); }
public static String preprocessQuery(Optional<String> catalog, Optional<String> schema, String query) throws QueryPreprocessorException { Duration timeout = DEFAULT_PREPROCESSOR_TIMEOUT; String timeoutEnvironment = nullToEmpty(System.getenv(ENV_PREPROCESSOR_TIMEOUT)).trim(); if (!timeoutEnvironment.isEmpty()) { timeout = Duration.valueOf(timeoutEnvironment); } String preprocessorCommand = System.getenv(ENV_PREPROCESSOR); if (emptyToNull(preprocessorCommand) == null) { return query; } return preprocessQuery(catalog, schema, query, ImmutableList.of("/bin/sh", "-c", preprocessorCommand), timeout); }
public void testNullToEmpty() { assertEquals("", Strings.nullToEmpty(null)); assertEquals("", Strings.nullToEmpty("")); assertEquals("a", Strings.nullToEmpty("a")); }
public static HdfsParquetDataSource buildHdfsParquetDataSource(FileSystem fileSystem, Path path, long start, long length, long fileSize, FileFormatDataSourceStats stats) { try { FSDataInputStream inputStream = fileSystem.open(path); return new HdfsParquetDataSource(new ParquetDataSourceId(path.toString()), fileSize, inputStream, stats); } catch (Exception e) { if (nullToEmpty(e.getMessage()).trim().equals("Filesystem closed") || e instanceof FileNotFoundException) { throw new PrestoException(HIVE_CANNOT_OPEN_SPLIT, e); } throw new PrestoException(HIVE_CANNOT_OPEN_SPLIT, format("Error opening Hive split %s (offset=%s, length=%s): %s", path, start, length, e.getMessage()), e); } }
public void assertFails(@Language("SQL") String sql, @Language("RegExp") String expectedMessageRegExp) { try { runner.execute(runner.getDefaultSession(), sql).toTestTypes(); fail(format("Expected query to fail: %s", sql)); } catch (RuntimeException exception) { if (!nullToEmpty(exception.getMessage()).matches(expectedMessageRegExp)) { fail(format("Expected exception message '%s' to match '%s' for query: %s", exception.getMessage(), expectedMessageRegExp, sql), exception); } } }
public static void fromMetastoreApiStorageDescriptor(StorageDescriptor storageDescriptor, Storage.Builder builder, String tablePartitionName) { SerDeInfo serdeInfo = storageDescriptor.getSerdeInfo(); if (serdeInfo == null) { throw new PrestoException(HIVE_INVALID_METADATA, "Table storage descriptor is missing SerDe info"); } builder.setStorageFormat(StorageFormat.createNullable(serdeInfo.getSerializationLib(), storageDescriptor.getInputFormat(), storageDescriptor.getOutputFormat())) .setLocation(nullToEmpty(storageDescriptor.getLocation())) .setBucketProperty(HiveBucketProperty.fromStorageDescriptor(storageDescriptor, tablePartitionName)) .setSkewed(storageDescriptor.isSetSkewedInfo() && storageDescriptor.getSkewedInfo().isSetSkewedColNames() && !storageDescriptor.getSkewedInfo().getSkewedColNames().isEmpty()) .setSerdeParameters(serdeInfo.getParameters() == null ? ImmutableMap.of() : serdeInfo.getParameters()); }