@Test public void testCastReplace() { String originString = "ignore EXTRACT(YEAR FROM CAST(KYLIN_CAL_DT.CAL_DT AS INTEGER)) ignore"; String replacedString = HivePushDownConverter.castReplace(originString); assertEquals("ignore EXTRACT(YEAR FROM CAST(KYLIN_CAL_DT.CAL_DT AS int)) ignore", replacedString); }
public static String castReplace(String originString) { Matcher castMatcher = CAST_PATTERN.matcher(originString); String replacedString = originString; while (castMatcher.find()) { String castStr = castMatcher.group(); String type = castMatcher.group(2); String supportedType = ""; switch (type.toUpperCase(Locale.ROOT)) { case "INTEGER": supportedType = "int"; break; case "SHORT": supportedType = "smallint"; break; case "LONG": supportedType = "bigint"; break; default: supportedType = type; } if (!supportedType.equals(type)) { String replacedCastStr = castStr.replace(type, supportedType); replacedString = replaceString(replacedString, castStr, replacedCastStr); } } return replacedString; }
HivePushDownConverter implements IPushDownConverter { public static String castReplace(String originString) { Matcher castMatcher = CAST_PATTERN.matcher(originString); String replacedString = originString; while (castMatcher.find()) { String castStr = castMatcher.group(); String type = castMatcher.group(2); String supportedType = ""; switch (type.toUpperCase(Locale.ROOT)) { case "INTEGER": supportedType = "int"; break; case "SHORT": supportedType = "smallint"; break; case "LONG": supportedType = "bigint"; break; default: supportedType = type; } if (!supportedType.equals(type)) { String replacedCastStr = castStr.replace(type, supportedType); replacedString = replaceString(replacedString, castStr, replacedCastStr); } } return replacedString; } }
HivePushDownConverter implements IPushDownConverter { public static String castReplace(String originString) { Matcher castMatcher = CAST_PATTERN.matcher(originString); String replacedString = originString; while (castMatcher.find()) { String castStr = castMatcher.group(); String type = castMatcher.group(2); String supportedType = ""; switch (type.toUpperCase(Locale.ROOT)) { case "INTEGER": supportedType = "int"; break; case "SHORT": supportedType = "smallint"; break; case "LONG": supportedType = "bigint"; break; default: supportedType = type; } if (!supportedType.equals(type)) { String replacedCastStr = castStr.replace(type, supportedType); replacedString = replaceString(replacedString, castStr, replacedCastStr); } } return replacedString; }  }
HivePushDownConverter implements IPushDownConverter { public static String castReplace(String originString) { Matcher castMatcher = CAST_PATTERN.matcher(originString); String replacedString = originString; while (castMatcher.find()) { String castStr = castMatcher.group(); String type = castMatcher.group(2); String supportedType = ""; switch (type.toUpperCase(Locale.ROOT)) { case "INTEGER": supportedType = "int"; break; case "SHORT": supportedType = "smallint"; break; case "LONG": supportedType = "bigint"; break; default: supportedType = type; } if (!supportedType.equals(type)) { String replacedCastStr = castStr.replace(type, supportedType); replacedString = replaceString(replacedString, castStr, replacedCastStr); } } 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 castReplace(String originString) { Matcher castMatcher = CAST_PATTERN.matcher(originString); String replacedString = originString; while (castMatcher.find()) { String castStr = castMatcher.group(); String type = castMatcher.group(2); String supportedType = ""; switch (type.toUpperCase(Locale.ROOT)) { case "INTEGER": supportedType = "int"; break; case "SHORT": supportedType = "smallint"; break; case "LONG": supportedType = "bigint"; break; default: supportedType = type; } if (!supportedType.equals(type)) { String replacedCastStr = castStr.replace(type, supportedType); replacedString = replaceString(replacedString, castStr, replacedCastStr); } } 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);  }