@Test public void testappendLimitOffsetToSql() { { String sql = "select ( date '2001-09-28' + interval floor(1.2) day) from test_kylin_fact"; String newsql = QueryUtil.appendLimitOffsetToSql(sql, 100, 100); Assert.assertEquals( "select * from (select ( date '2001-09-28' + interval floor(1.2) day) from test_kylin_fact) limit 100 offset 100", newsql); } { String sql = "select ( date '2001-09-28' + interval floor(1.2) day) from test_kylin_fact"; String newsql = QueryUtil.appendLimitOffsetToSql(sql, 0, 0); Assert.assertEquals( "select ( date '2001-09-28' + interval floor(1.2) day) from test_kylin_fact", newsql); } { String sql = "explain plan for select ( date '2001-09-28' + interval floor(1.2) day) from test_kylin_fact"; String newsql = QueryUtil.appendLimitOffsetToSql(sql, 100, 100); Assert.assertEquals( "explain plan for select ( date '2001-09-28' + interval floor(1.2) day) from test_kylin_fact limit 100 offset 100", newsql); } { String sql = "explain plan for select ( date '2001-09-28' + interval floor(1.2) day) from test_kylin_fact"; String newsql = QueryUtil.appendLimitOffsetToSql(sql, 0, 0); Assert.assertEquals( "explain plan for select ( date '2001-09-28' + interval floor(1.2) day) from test_kylin_fact", newsql); } }
public static String appendLimitOffsetToSql(String sql, int limit, int offset) { String retSql = sql; String prefixSql = "select * from ("; String suffixSql = ")"; if (StringUtils.startsWithIgnoreCase(sql, KEYWORD_EXPLAIN) || StringUtils.startsWithIgnoreCase(sql, KEYWORD_WITH)) { prefixSql = ""; suffixSql = ""; } if (0 != limit && 0 != offset) { retSql = prefixSql + sql + suffixSql + " limit " + String.valueOf(limit) + " offset " + String.valueOf(offset); } else if (0 == limit && 0 != offset) { retSql = prefixSql + sql + suffixSql + " offset " + String.valueOf(offset); } else if (0 != limit && 0 == offset) { retSql = prefixSql + sql + suffixSql + " limit " + String.valueOf(limit); } else { } return retSql; }
QueryUtil { public static String appendLimitOffsetToSql(String sql, int limit, int offset) { String retSql = sql; String prefixSql = "select * from ("; String suffixSql = ")"; if (StringUtils.startsWithIgnoreCase(sql, KEYWORD_EXPLAIN) || StringUtils.startsWithIgnoreCase(sql, KEYWORD_WITH)) { prefixSql = ""; suffixSql = ""; } if (0 != limit && 0 != offset) { retSql = prefixSql + sql + suffixSql + " limit " + String.valueOf(limit) + " offset " + String.valueOf(offset); } else if (0 == limit && 0 != offset) { retSql = prefixSql + sql + suffixSql + " offset " + String.valueOf(offset); } else if (0 != limit && 0 == offset) { retSql = prefixSql + sql + suffixSql + " limit " + String.valueOf(limit); } else { } return retSql; } }
QueryUtil { public static String appendLimitOffsetToSql(String sql, int limit, int offset) { String retSql = sql; String prefixSql = "select * from ("; String suffixSql = ")"; if (StringUtils.startsWithIgnoreCase(sql, KEYWORD_EXPLAIN) || StringUtils.startsWithIgnoreCase(sql, KEYWORD_WITH)) { prefixSql = ""; suffixSql = ""; } if (0 != limit && 0 != offset) { retSql = prefixSql + sql + suffixSql + " limit " + String.valueOf(limit) + " offset " + String.valueOf(offset); } else if (0 == limit && 0 != offset) { retSql = prefixSql + sql + suffixSql + " offset " + String.valueOf(offset); } else if (0 != limit && 0 == offset) { retSql = prefixSql + sql + suffixSql + " limit " + String.valueOf(limit); } else { } return retSql; } private  QueryUtil(); }
QueryUtil { public static String appendLimitOffsetToSql(String sql, int limit, int offset) { String retSql = sql; String prefixSql = "select * from ("; String suffixSql = ")"; if (StringUtils.startsWithIgnoreCase(sql, KEYWORD_EXPLAIN) || StringUtils.startsWithIgnoreCase(sql, KEYWORD_WITH)) { prefixSql = ""; suffixSql = ""; } if (0 != limit && 0 != offset) { retSql = prefixSql + sql + suffixSql + " limit " + String.valueOf(limit) + " offset " + String.valueOf(offset); } else if (0 == limit && 0 != offset) { retSql = prefixSql + sql + suffixSql + " offset " + String.valueOf(offset); } else if (0 != limit && 0 == offset) { retSql = prefixSql + sql + suffixSql + " limit " + String.valueOf(limit); } else { } return retSql; } private  QueryUtil(); static String appendLimitOffsetToSql(String sql, int limit, int offset); @Deprecated static String massageSql(String sql, String project, int limit, int offset, String defaultSchema); static String massageSql(String sql, String project, int limit, int offset, String defaultSchema,
            String catalog); static String makeErrorMsgUserFriendly(Throwable e); static String makeErrorMsgUserFriendly(String errorMsg); static boolean isSelectStatement(String sql); static String removeCommentInSql(String sql1); }
QueryUtil { public static String appendLimitOffsetToSql(String sql, int limit, int offset) { String retSql = sql; String prefixSql = "select * from ("; String suffixSql = ")"; if (StringUtils.startsWithIgnoreCase(sql, KEYWORD_EXPLAIN) || StringUtils.startsWithIgnoreCase(sql, KEYWORD_WITH)) { prefixSql = ""; suffixSql = ""; } if (0 != limit && 0 != offset) { retSql = prefixSql + sql + suffixSql + " limit " + String.valueOf(limit) + " offset " + String.valueOf(offset); } else if (0 == limit && 0 != offset) { retSql = prefixSql + sql + suffixSql + " offset " + String.valueOf(offset); } else if (0 != limit && 0 == offset) { retSql = prefixSql + sql + suffixSql + " limit " + String.valueOf(limit); } else { } return retSql; } private  QueryUtil(); static String appendLimitOffsetToSql(String sql, int limit, int offset); @Deprecated static String massageSql(String sql, String project, int limit, int offset, String defaultSchema); static String massageSql(String sql, String project, int limit, int offset, String defaultSchema,
            String catalog); static String makeErrorMsgUserFriendly(Throwable e); static String makeErrorMsgUserFriendly(String errorMsg); static boolean isSelectStatement(String sql); static String removeCommentInSql(String sql1);  }