com.alibaba.druid.sql.visitor.ParameterizedOutputVisitorUtils Java Examples

The following examples show how to use com.alibaba.druid.sql.visitor.ParameterizedOutputVisitorUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UserSqlHighStat.java    From Mycat2 with GNU General Public License v3.0 5 votes vote down vote up
public String mergeSql(String sql) {
  try {
    String newSql = ParameterizedOutputVisitorUtils.parameterize(sql, "mysql");
    return fixSql(newSql);
  } catch (Exception e) {
    LOGGER.warn("user sql high parse:{} error",sql, e);
    return null;
  }
}
 
Example #2
Source File: SQLStatistic.java    From fiery with Apache License 2.0 4 votes vote down vote up
public void addSqlMap(String sqlStr, Long hour, Double costTime) {

        if (sqlStr == null || sqlStr.trim().length() == 0) {
            return;
        }

        //clean up the parameter of sql
        String sqlStrPure = SQLUtils.format(sqlStr, JdbcConstants.MYSQL);
        sqlStrPure = ParameterizedOutputVisitorUtils.parameterize(sqlStrPure, JdbcConstants.MYSQL);
        sqlStrPure = sqlStrPure.replaceAll("\\s+", " ");

        SimHash hash1;
        try {
            hash1 = new SimHash(sqlStrPure, 64);
        } catch (Exception e) {
            log.debug(e.getMessage());
            return;
        }

        boolean issame = false;
        for (Map.Entry<SQLKey, Map<Long, SqlStatisticStruct>> entry : _sqlMap.entrySet()) {

            Integer similityThreadHold;
            if (sqlStrPure.length() < 100) {
                similityThreadHold = 8;
            } else if (sqlStrPure.length() < 500) {
                similityThreadHold = 5;
            } else {
                similityThreadHold = 3;
            }

            if (entry.getKey().getHash().hammingDistance(hash1) <= similityThreadHold) {
                addHourMap(entry.getValue(), entry.getKey().getSql(), hour, costTime);
                issame = true;
                break;
            }
        }
        if (!issame) {
            Map<Long, SqlStatisticStruct> hourMap = new HashMap<Long, SqlStatisticStruct>();
            addHourMap(hourMap, sqlStr, hour, costTime);
            SQLKey sqlKey = new SQLKey();
            sqlKey.setHash(hash1);
            sqlKey.setPureSql(sqlStrPure);
            sqlKey.setSql(sqlStr);
            _sqlMap.put(sqlKey, hourMap);
        }
    }
 
Example #3
Source File: SqlResultSizeRecorder.java    From Mycat2 with GNU General Public License v3.0 4 votes vote down vote up
public String mergeSql(String sql) {

String newSql = ParameterizedOutputVisitorUtils.parameterize(sql, "mysql");
return fixSql( newSql );
  }
 
Example #4
Source File: StatSqlParser.java    From dble with GNU General Public License v2.0 4 votes vote down vote up
public String mergeSql(String sql) {

        String newSql = ParameterizedOutputVisitorUtils.parameterize(sql, "mysql");
        return fixSql(newSql);
    }