@Test public void testAddLimit() { 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" + " limit 10000)t\n"; String replacedString = HivePushDownConverter.addLimit(originString); assertEquals(originString.concat(" limit 1"), replacedString); }
public static String addLimit(String originString) { Matcher selectMatcher = SELECT_PATTERN.matcher(originString); Matcher limitMatcher = LIMIT_PATTERN.matcher(originString); String replacedString = originString; if (selectMatcher.find() && !limitMatcher.find()) { if (originString.endsWith(";")) { replacedString = originString.replaceAll(";+$", ""); } replacedString = replacedString.concat(" limit 1"); } return replacedString; }
HivePushDownConverter implements IPushDownConverter { public static String addLimit(String originString) { Matcher selectMatcher = SELECT_PATTERN.matcher(originString); Matcher limitMatcher = LIMIT_PATTERN.matcher(originString); String replacedString = originString; if (selectMatcher.find() && !limitMatcher.find()) { if (originString.endsWith(";")) { replacedString = originString.replaceAll(";+$", ""); } replacedString = replacedString.concat(" limit 1"); } return replacedString; } }
HivePushDownConverter implements IPushDownConverter { public static String addLimit(String originString) { Matcher selectMatcher = SELECT_PATTERN.matcher(originString); Matcher limitMatcher = LIMIT_PATTERN.matcher(originString); String replacedString = originString; if (selectMatcher.find() && !limitMatcher.find()) { if (originString.endsWith(";")) { replacedString = originString.replaceAll(";+$", ""); } replacedString = replacedString.concat(" limit 1"); } return replacedString; }  }
HivePushDownConverter implements IPushDownConverter { public static String addLimit(String originString) { Matcher selectMatcher = SELECT_PATTERN.matcher(originString); Matcher limitMatcher = LIMIT_PATTERN.matcher(originString); String replacedString = originString; if (selectMatcher.find() && !limitMatcher.find()) { if (originString.endsWith(";")) { replacedString = originString.replaceAll(";+$", ""); } replacedString = replacedString.concat(" limit 1"); } 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 addLimit(String originString) { Matcher selectMatcher = SELECT_PATTERN.matcher(originString); Matcher limitMatcher = LIMIT_PATTERN.matcher(originString); String replacedString = originString; if (selectMatcher.find() && !limitMatcher.find()) { if (originString.endsWith(";")) { replacedString = originString.replaceAll(";+$", ""); } replacedString = replacedString.concat(" limit 1"); } 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);  }