@Test public void testExtractReplace() { String originString = "ignore EXTRACT(YEAR FROM KYLIN_CAL_DT.CAL_DT) ignore"; String replacedString = HivePushDownConverter.extractReplace(originString); assertEquals("ignore YEAR(KYLIN_CAL_DT.CAL_DT) ignore", replacedString); }
public static String extractReplace(String originString) { Matcher extractMatcher = EXTRACT_PATTERN.matcher(originString); String replacedString = originString; Map<Integer, Integer> parenthesesPairs = null; while (extractMatcher.find()) { if (parenthesesPairs == null) { parenthesesPairs = findParenthesesPairs(originString); } String functionStr = extractMatcher.group(2); int startIdx = extractMatcher.end(3); int endIdx = parenthesesPairs.get(extractMatcher.start(1)); String extractInner = originString.substring(startIdx, endIdx); int originStart = extractMatcher.start(0); int originEnd = endIdx + 1; replacedString = replaceString(replacedString, originString.substring(originStart, originEnd), functionStr + "(" + extractInner + ")"); } return replacedString; }
HivePushDownConverter implements IPushDownConverter { public static String extractReplace(String originString) { Matcher extractMatcher = EXTRACT_PATTERN.matcher(originString); String replacedString = originString; Map<Integer, Integer> parenthesesPairs = null; while (extractMatcher.find()) { if (parenthesesPairs == null) { parenthesesPairs = findParenthesesPairs(originString); } String functionStr = extractMatcher.group(2); int startIdx = extractMatcher.end(3); int endIdx = parenthesesPairs.get(extractMatcher.start(1)); String extractInner = originString.substring(startIdx, endIdx); int originStart = extractMatcher.start(0); int originEnd = endIdx + 1; replacedString = replaceString(replacedString, originString.substring(originStart, originEnd), functionStr + "(" + extractInner + ")"); } return replacedString; } }
HivePushDownConverter implements IPushDownConverter { public static String extractReplace(String originString) { Matcher extractMatcher = EXTRACT_PATTERN.matcher(originString); String replacedString = originString; Map<Integer, Integer> parenthesesPairs = null; while (extractMatcher.find()) { if (parenthesesPairs == null) { parenthesesPairs = findParenthesesPairs(originString); } String functionStr = extractMatcher.group(2); int startIdx = extractMatcher.end(3); int endIdx = parenthesesPairs.get(extractMatcher.start(1)); String extractInner = originString.substring(startIdx, endIdx); int originStart = extractMatcher.start(0); int originEnd = endIdx + 1; replacedString = replaceString(replacedString, originString.substring(originStart, originEnd), functionStr + "(" + extractInner + ")"); } return replacedString; }  }
HivePushDownConverter implements IPushDownConverter { public static String extractReplace(String originString) { Matcher extractMatcher = EXTRACT_PATTERN.matcher(originString); String replacedString = originString; Map<Integer, Integer> parenthesesPairs = null; while (extractMatcher.find()) { if (parenthesesPairs == null) { parenthesesPairs = findParenthesesPairs(originString); } String functionStr = extractMatcher.group(2); int startIdx = extractMatcher.end(3); int endIdx = parenthesesPairs.get(extractMatcher.start(1)); String extractInner = originString.substring(startIdx, endIdx); int originStart = extractMatcher.start(0); int originEnd = endIdx + 1; replacedString = replaceString(replacedString, originString.substring(originStart, originEnd), functionStr + "(" + extractInner + ")"); } return replacedString; }  static String replaceString(String originString, String fromString, String toString); static String extractReplace(String originString); static String castReplace(String originString); static String subqueryReplace(String originString); static String timestampAddDiffReplace(String originString); static String concatReplace(String originString); static String addLimit(String originString); static String doConvert(String originStr, boolean isPrepare); @Override String convert(String originSql, String project, String defaultSchema, boolean isPrepare); }
HivePushDownConverter implements IPushDownConverter { public static String extractReplace(String originString) { Matcher extractMatcher = EXTRACT_PATTERN.matcher(originString); String replacedString = originString; Map<Integer, Integer> parenthesesPairs = null; while (extractMatcher.find()) { if (parenthesesPairs == null) { parenthesesPairs = findParenthesesPairs(originString); } String functionStr = extractMatcher.group(2); int startIdx = extractMatcher.end(3); int endIdx = parenthesesPairs.get(extractMatcher.start(1)); String extractInner = originString.substring(startIdx, endIdx); int originStart = extractMatcher.start(0); int originEnd = endIdx + 1; replacedString = replaceString(replacedString, originString.substring(originStart, originEnd), functionStr + "(" + extractInner + ")"); } return replacedString; }  static String replaceString(String originString, String fromString, String toString); static String extractReplace(String originString); static String castReplace(String originString); static String subqueryReplace(String originString); static String timestampAddDiffReplace(String originString); static String concatReplace(String originString); static String addLimit(String originString); static String doConvert(String originStr, boolean isPrepare); @Override String convert(String originSql, String project, String defaultSchema, boolean isPrepare);  }