private String fullMetricName(final String name) { return StringUtils.replace(name, "org.apache.calcite.avatica", "avatica").replace('.', '/'); } }
private String withServiceName(String taskAsString, String serviceName) { return StringUtils.replace(taskAsString, EVENT_RECEIVER_SERVICE_PREFIX, serviceName); }
/** * Encodes a String in application/x-www-form-urlencoded format, with one exception: * "+" in the encoded form is replaced with "%20". * * application/x-www-form-urlencoded encodes spaces as "+", but we use this to encode non-form data as well. * * @param s String to be encoded * @return application/x-www-form-urlencoded format encoded String, but with "+" replaced with "%20". */ @Nullable public static String urlEncode(String s) { if (s == null) { return null; } try { return StringUtils.replace(URLEncoder.encode(s, "UTF-8"), "+", "%20"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
private String withDataSource(String taskAsString, String dataSource) { return StringUtils.replace(taskAsString, "%%DATASOURCE%%", dataSource); }
protected File computeCorruptedFileDumpDir(File persistDir, DataSchema schema) { return new File( StringUtils.replace( persistDir.getAbsolutePath(), schema.getDataSource(), "corrupted" + File.pathSeparator + schema.getDataSource() ) ); }
String setShutOffTime(String taskAsString, DateTime time) { return StringUtils.replace(taskAsString, "#SHUTOFFTIME", time.toString()); }
private String setShutOffTime(String taskAsString, DateTime time) { return StringUtils.replace(taskAsString, "#SHUTOFFTIME", time.toString()); }
@Override public String getUserDataBase64() { final String finalData; if (versionReplacementString != null && version != null) { finalData = StringUtils.replace(data, versionReplacementString, version); } else { finalData = data; } return StringUtils.encodeBase64String(StringUtils.toUtf8(finalData)); }
@JsonCreator public OrcHadoopInputRowParser( @JsonProperty("parseSpec") ParseSpec parseSpec, @JsonProperty("typeString") String typeString, @JsonProperty("mapFieldNameFormat") String mapFieldNameFormat ) { this.parseSpec = parseSpec; this.typeString = typeString == null ? typeStringFromParseSpec(parseSpec) : typeString; this.mapFieldNameFormat = mapFieldNameFormat == null || !mapFieldNameFormat.contains(MAP_PARENT_TAG) || !mapFieldNameFormat.contains(MAP_CHILD_TAG) ? DEFAULT_MAP_FIELD_NAME_FORMAT : mapFieldNameFormat; this.mapParentFieldNameFormat = StringUtils.replace(this.mapFieldNameFormat, MAP_PARENT_TAG, "%s"); this.dimensions = parseSpec.getDimensionsSpec().getDimensionNames(); this.oip = makeObjectInspector(this.typeString); }
@Override public URI apply(Event event) throws URISyntaxException { Map<String, Object> eventMap = event.toMap(); String processedUri = uriPattern; for (String key : params) { Object paramValue = eventMap.get(key); if (paramValue == null) { throw new IAE( "ParametrizedUriExtractor with pattern %s requires %s to be set in event, but found %s", uriPattern, key, eventMap ); } processedUri = StringUtils.replace(processedUri, StringUtils.format("{%s}", key), paramValue.toString()); } return new URI(processedUri); }
@Override protected String rewriteURI(HttpServletRequest request, String scheme, String host) { String uri = super.rewriteURI(request, scheme, host); if (uri.contains("/druid/v2")) { return URI.create(StringUtils.replace(uri, "/druid/v2", "/default")).toString(); } return URI.create(StringUtils.replace(uri, "/proxy", "")).toString(); } });
private static UriExtractor makeUriExtractor(ParametrizedUriEmitterConfig config) { final String baseUri = config.getRecipientBaseUrlPattern(); final ParametrizedUriExtractor parametrizedUriExtractor = new ParametrizedUriExtractor(baseUri); UriExtractor uriExtractor = parametrizedUriExtractor; if (ONLY_FEED_PARAM.equals(parametrizedUriExtractor.getParams())) { uriExtractor = new FeedUriExtractor(StringUtils.replace(baseUri, "{feed}", "%s")); } return uriExtractor; }
@Test public void testReplace() { Assert.assertEquals("x1x2x3x", StringUtils.replace("123", "", "x")); Assert.assertEquals("12345", StringUtils.replace("123,", ",", "45")); Assert.assertEquals("", StringUtils.replace("", "a", "bb")); Assert.assertEquals("bb", StringUtils.replace("a", "a", "bb")); Assert.assertEquals("bba", StringUtils.replace("aaa", "aa", "bb")); Assert.assertEquals("bcb", StringUtils.replace("aacaa", "aa", "b")); Assert.assertEquals("bb", StringUtils.replace("aaaa", "aa", "b")); Assert.assertEquals("", StringUtils.replace("aaaa", "aa", "")); }
private void getMapObject(String parentName, MapObjectInspector mapObjectInspector, Object mapObject, Map<String, Object> parsedMap) { if (mapObjectInspector.getMapSize(mapObject) < 0) { return; } String mapChildFieldNameFormat = StringUtils.replace( StringUtils.format(mapParentFieldNameFormat, parentName), MAP_CHILD_TAG, "%s" ); Map objectMap = mapObjectInspector.getMap(mapObject); PrimitiveObjectInspector key = (PrimitiveObjectInspector) mapObjectInspector.getMapKeyObjectInspector(); PrimitiveObjectInspector value = (PrimitiveObjectInspector) mapObjectInspector.getMapValueObjectInspector(); objectMap.forEach((k, v) -> { String resolvedFieldName = StringUtils.format(mapChildFieldNameFormat, key.getPrimitiveJavaObject(k).toString()); parsedMap.put(resolvedFieldName, value.getPrimitiveJavaObject(v)); }); }
public static void setUpCgroups( File procDir, File cgroupDir ) throws IOException { final File procMountsTemplate = new File(procDir, "mounts.template"); final File procMounts = new File(procDir, "mounts"); copyResource("/proc.mounts", procMountsTemplate); final String procMountsString = StringUtils.fromUtf8(Files.readAllBytes(procMountsTemplate.toPath())); Files.write( procMounts.toPath(), StringUtils.toUtf8(StringUtils.replace(procMountsString, "/sys/fs/cgroup", cgroupDir.getAbsolutePath())) ); Assert.assertTrue(new File( cgroupDir, "cpu,cpuacct/system.slice/some.service/f12ba7e0-fa16-462e-bb9d-652ccc27f0ee" ).mkdirs()); copyResource("/proc.pid.cgroup", new File(procDir, "cgroup")); }
@Override public ExprEval apply(List<Expr> args, Expr.ObjectBinding bindings) { if (args.size() != 3) { throw new IAE("Function[%s] needs 3 arguments", name()); } final String arg = args.get(0).eval(bindings).asString(); final String pattern = NullHandling.nullToEmptyIfNeeded(args.get(1).eval(bindings).asString()); final String replacement = NullHandling.nullToEmptyIfNeeded(args.get(2).eval(bindings).asString()); if (arg == null) { return ExprEval.of(NullHandling.defaultStringValue()); } return ExprEval.of(StringUtils.replace(arg, pattern, replacement)); } }
private void compactData(boolean keepSegmentGranularity) throws Exception { final String template = getTaskAsString(COMPACTION_TASK); String taskSpec = StringUtils.replace(template, "${KEEP_SEGMENT_GRANULARITY}", Boolean.toString(keepSegmentGranularity)); taskSpec = StringUtils.replace(taskSpec, "%%DATASOURCE%%", fullDatasourceName); final String taskID = indexer.submitTask(taskSpec); LOG.info("TaskID for compaction task %s", taskID); indexer.waitUntilTaskCompletes(taskID); RetryUtil.retryUntilTrue( () -> coordinator.areSegmentsLoaded(fullDatasourceName), "Segment Compaction" ); }
@Test public void testIndexData() { try { loadData(); String queryResponseTemplate; try { InputStream is = AbstractITBatchIndexTest.class.getResourceAsStream(WIKITICKER_QUERIES_RESOURCE); queryResponseTemplate = IOUtils.toString(is, "UTF-8"); } catch (IOException e) { throw new ISE(e, "could not read query file: %s", WIKITICKER_QUERIES_RESOURCE); } queryResponseTemplate = StringUtils.replace( queryResponseTemplate, "%%DATASOURCE%%", fullDatasourceName ); queryHelper.testQueriesFromString(queryResponseTemplate, 2); } catch (Exception e) { LOG.error(e, "Error while testing"); throw Throwables.propagate(e); } }
private void loadData() throws Exception { String taskSpec = getTaskAsString(WIKITICKER_INDEX_TASK); taskSpec = StringUtils.replace(taskSpec, "%%DATASOURCE%%", fullDatasourceName); final String taskID = indexer.submitTask(taskSpec); LOG.info("TaskID for loading index task %s", taskID); indexer.waitUntilTaskCompletes(taskID); RetryUtil.retryUntilTrue( () -> coordinator.areSegmentsLoaded(fullDatasourceName), "Segment Load" ); } }
private void loadData() throws Exception { String taskSpec = getTaskAsString(INDEX_TASK); taskSpec = StringUtils.replace(taskSpec, "%%DATASOURCE%%", fullDatasourceName); final String taskID = indexer.submitTask(taskSpec); LOG.info("TaskID for loading index task %s", taskID); indexer.waitUntilTaskCompletes(taskID); RetryUtil.retryUntilTrue( () -> coordinator.areSegmentsLoaded(fullDatasourceName), "Segment Load" ); }