@Test public void testSubqueryReplace4() { String originString = "select t.TRANS_ID from (\n" + " select * from test_kylin_fact s inner join TEST_ACCOUNT a \n" + " on s.BUYER_ID = a.ACCOUNT_ID inner join TEST_COUNTRY c on c.COUNTRY = a.ACCOUNT_COUNTRY\n" + " )t\n" + "LIMIT 50000"; String replacedString = HivePushDownConverter.subqueryReplace(originString); assertEquals(originString, replacedString); }
public static String subqueryReplace(String originString) { Matcher subqueryMatcher = FROM_PATTERN.matcher(originString); String replacedString = originString; Map<Integer, Integer> parenthesesPairs = null; while (subqueryMatcher.find()) { if (parenthesesPairs == null) { parenthesesPairs = findParenthesesPairs(originString); } int startIdx = subqueryMatcher.start(1); int endIdx = parenthesesPairs.get(startIdx) + 1; Matcher aliasMatcher = ALIAS_PATTERN.matcher(originString.substring(endIdx)); if (aliasMatcher.find()) { String aliasCandidate = aliasMatcher.group(1); if (aliasCandidate != null && !sqlKeyWordsExceptAS.contains(aliasCandidate.toUpperCase(Locale.ROOT))) { continue; } replacedString = replaceString(replacedString, originString.substring(startIdx, endIdx), originString.substring(startIdx, endIdx) + " as alias"); } } return replacedString; }
HivePushDownConverter implements IPushDownConverter { public static String subqueryReplace(String originString) { Matcher subqueryMatcher = FROM_PATTERN.matcher(originString); String replacedString = originString; Map<Integer, Integer> parenthesesPairs = null; while (subqueryMatcher.find()) { if (parenthesesPairs == null) { parenthesesPairs = findParenthesesPairs(originString); } int startIdx = subqueryMatcher.start(1); int endIdx = parenthesesPairs.get(startIdx) + 1; Matcher aliasMatcher = ALIAS_PATTERN.matcher(originString.substring(endIdx)); if (aliasMatcher.find()) { String aliasCandidate = aliasMatcher.group(1); if (aliasCandidate != null && !sqlKeyWordsExceptAS.contains(aliasCandidate.toUpperCase(Locale.ROOT))) { continue; } replacedString = replaceString(replacedString, originString.substring(startIdx, endIdx), originString.substring(startIdx, endIdx) + " as alias"); } } return replacedString; } }
HivePushDownConverter implements IPushDownConverter { public static String subqueryReplace(String originString) { Matcher subqueryMatcher = FROM_PATTERN.matcher(originString); String replacedString = originString; Map<Integer, Integer> parenthesesPairs = null; while (subqueryMatcher.find()) { if (parenthesesPairs == null) { parenthesesPairs = findParenthesesPairs(originString); } int startIdx = subqueryMatcher.start(1); int endIdx = parenthesesPairs.get(startIdx) + 1; Matcher aliasMatcher = ALIAS_PATTERN.matcher(originString.substring(endIdx)); if (aliasMatcher.find()) { String aliasCandidate = aliasMatcher.group(1); if (aliasCandidate != null && !sqlKeyWordsExceptAS.contains(aliasCandidate.toUpperCase(Locale.ROOT))) { continue; } replacedString = replaceString(replacedString, originString.substring(startIdx, endIdx), originString.substring(startIdx, endIdx) + " as alias"); } } return replacedString; }  }
HivePushDownConverter implements IPushDownConverter { public static String subqueryReplace(String originString) { Matcher subqueryMatcher = FROM_PATTERN.matcher(originString); String replacedString = originString; Map<Integer, Integer> parenthesesPairs = null; while (subqueryMatcher.find()) { if (parenthesesPairs == null) { parenthesesPairs = findParenthesesPairs(originString); } int startIdx = subqueryMatcher.start(1); int endIdx = parenthesesPairs.get(startIdx) + 1; Matcher aliasMatcher = ALIAS_PATTERN.matcher(originString.substring(endIdx)); if (aliasMatcher.find()) { String aliasCandidate = aliasMatcher.group(1); if (aliasCandidate != null && !sqlKeyWordsExceptAS.contains(aliasCandidate.toUpperCase(Locale.ROOT))) { continue; } replacedString = replaceString(replacedString, originString.substring(startIdx, endIdx), originString.substring(startIdx, endIdx) + " as alias"); } } 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 subqueryReplace(String originString) { Matcher subqueryMatcher = FROM_PATTERN.matcher(originString); String replacedString = originString; Map<Integer, Integer> parenthesesPairs = null; while (subqueryMatcher.find()) { if (parenthesesPairs == null) { parenthesesPairs = findParenthesesPairs(originString); } int startIdx = subqueryMatcher.start(1); int endIdx = parenthesesPairs.get(startIdx) + 1; Matcher aliasMatcher = ALIAS_PATTERN.matcher(originString.substring(endIdx)); if (aliasMatcher.find()) { String aliasCandidate = aliasMatcher.group(1); if (aliasCandidate != null && !sqlKeyWordsExceptAS.contains(aliasCandidate.toUpperCase(Locale.ROOT))) { continue; } replacedString = replaceString(replacedString, originString.substring(startIdx, endIdx), originString.substring(startIdx, endIdx) + " as alias"); } } 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);  }