Java Code Examples for org.apache.kylin.rest.request.PrepareSqlRequest#StateParam
The following examples show how to use
org.apache.kylin.rest.request.PrepareSqlRequest#StateParam .
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: CubeService.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
private List<List<String>> getPrepareQueryResult(String cubeName, String sql) { PrepareSqlRequest sqlRequest = new PrepareSqlRequest(); sqlRequest.setProject(MetricsManager.SYSTEM_PROJECT); PrepareSqlRequest.StateParam[] params = new PrepareSqlRequest.StateParam[1]; params[0] = new PrepareSqlRequest.StateParam(); params[0].setClassName("java.lang.String"); params[0].setValue(cubeName); sqlRequest.setParams(params); sqlRequest.setSql(sql); return queryService.doQueryWithCache(sqlRequest, false).getResults(); }
Example 2
Source File: CubeService.java From kylin with Apache License 2.0 | 5 votes |
private List<List<String>> getPrepareQueryResult(String cubeName, String sql) { PrepareSqlRequest sqlRequest = new PrepareSqlRequest(); sqlRequest.setProject(MetricsManager.SYSTEM_PROJECT); PrepareSqlRequest.StateParam[] params = new PrepareSqlRequest.StateParam[1]; params[0] = new PrepareSqlRequest.StateParam(); params[0].setClassName("java.lang.String"); params[0].setValue(cubeName); sqlRequest.setParams(params); sqlRequest.setSql(sql); return queryService.doQueryWithCache(sqlRequest, false).getResults(); }
Example 3
Source File: QueryService.java From kylin-on-parquet-v2 with Apache License 2.0 | 4 votes |
/** * @param preparedState * @param param * @throws SQLException */ private void setParam(PreparedStatement preparedState, int index, PrepareSqlRequest.StateParam param) throws SQLException { boolean isNull = (null == param.getValue()); Class<?> clazz; try { clazz = Class.forName(param.getClassName()); } catch (ClassNotFoundException e) { throw new InternalErrorException(e); } Rep rep = Rep.of(clazz); switch (rep) { case PRIMITIVE_CHAR: case CHARACTER: case STRING: preparedState.setString(index, isNull ? null : String.valueOf(param.getValue())); break; case PRIMITIVE_INT: case INTEGER: preparedState.setInt(index, isNull ? 0 : Integer.parseInt(param.getValue())); break; case PRIMITIVE_SHORT: case SHORT: preparedState.setShort(index, isNull ? 0 : Short.parseShort(param.getValue())); break; case PRIMITIVE_LONG: case LONG: preparedState.setLong(index, isNull ? 0 : Long.parseLong(param.getValue())); break; case PRIMITIVE_FLOAT: case FLOAT: preparedState.setFloat(index, isNull ? 0 : Float.parseFloat(param.getValue())); break; case PRIMITIVE_DOUBLE: case DOUBLE: preparedState.setDouble(index, isNull ? 0 : Double.parseDouble(param.getValue())); break; case PRIMITIVE_BOOLEAN: case BOOLEAN: preparedState.setBoolean(index, !isNull && Boolean.parseBoolean(param.getValue())); break; case PRIMITIVE_BYTE: case BYTE: preparedState.setByte(index, isNull ? 0 : Byte.parseByte(param.getValue())); break; case JAVA_UTIL_DATE: case JAVA_SQL_DATE: preparedState.setDate(index, isNull ? null : java.sql.Date.valueOf(param.getValue())); break; case JAVA_SQL_TIME: preparedState.setTime(index, isNull ? null : Time.valueOf(param.getValue())); break; case JAVA_SQL_TIMESTAMP: preparedState.setTimestamp(index, isNull ? null : Timestamp.valueOf(param.getValue())); break; default: preparedState.setObject(index, isNull ? null : param.getValue()); } }
Example 4
Source File: DashboardService.java From kylin-on-parquet-v2 with Apache License 2.0 | 4 votes |
private PrepareSqlRequest createPrepareSqlRequest(String[] dimensions, String[] metrics, String category, Map<String, String> filterMap) { PrepareSqlRequest sqlRequest = new PrepareSqlRequest(); sqlRequest.setProject(MetricsManager.SYSTEM_PROJECT); StringBuffer baseSQL = new StringBuffer("select "); StringBuffer groupBy = new StringBuffer(""); if (dimensions != null && dimensions.length > 0) { groupBy.append(" group by "); StringBuffer dimensionSQL = new StringBuffer(""); for (String dimension : dimensions) { dimensionSQL.append(","); dimensionSQL.append(dimension); } baseSQL.append(dimensionSQL.substring(1)); groupBy.append(dimensionSQL.substring(1)); } if (metrics != null && metrics.length > 0) { StringBuffer metricSQL = new StringBuffer(""); for (String metric : metrics) { metricSQL.append(","); metricSQL.append(metric); } if (groupBy.length() > 0) { baseSQL.append(metricSQL); } else { baseSQL.append(metricSQL.substring(1)); } } baseSQL.append(" from "); baseSQL.append(category); if (filterMap != null && filterMap.size() > 0) { PrepareSqlRequest.StateParam[] params = new PrepareSqlRequest.StateParam[filterMap.size()]; int i = 0; StringBuffer filterSQL = new StringBuffer(" where "); Iterator<String> it = filterMap.keySet().iterator(); String filter = it.next(); filterSQL.append(filter); params[i] = new PrepareSqlRequest.StateParam(); params[i].setClassName("java.lang.String"); params[i++].setValue(filterMap.get(filter)); while (it.hasNext()) { filter = it.next(); filterSQL.append(" and "); filterSQL.append(filter); params[i] = new PrepareSqlRequest.StateParam(); params[i].setClassName("java.lang.String"); params[i++].setValue(filterMap.get(filter)); } baseSQL.append(filterSQL.toString()); sqlRequest.setParams(params); } baseSQL.append(groupBy); sqlRequest.setSql(baseSQL.toString()); return sqlRequest; }
Example 5
Source File: QueryService.java From kylin with Apache License 2.0 | 4 votes |
/** * @param preparedState * @param param * @throws SQLException */ private void setParam(PreparedStatement preparedState, int index, PrepareSqlRequest.StateParam param) throws SQLException { boolean isNull = (null == param.getValue()); Class<?> clazz; try { clazz = Class.forName(param.getClassName()); } catch (ClassNotFoundException e) { throw new InternalErrorException(e); } Rep rep = Rep.of(clazz); switch (rep) { case PRIMITIVE_CHAR: case CHARACTER: case STRING: preparedState.setString(index, isNull ? null : String.valueOf(param.getValue())); break; case PRIMITIVE_INT: case INTEGER: preparedState.setInt(index, isNull ? 0 : Integer.parseInt(param.getValue())); break; case PRIMITIVE_SHORT: case SHORT: preparedState.setShort(index, isNull ? 0 : Short.parseShort(param.getValue())); break; case PRIMITIVE_LONG: case LONG: preparedState.setLong(index, isNull ? 0 : Long.parseLong(param.getValue())); break; case PRIMITIVE_FLOAT: case FLOAT: preparedState.setFloat(index, isNull ? 0 : Float.parseFloat(param.getValue())); break; case PRIMITIVE_DOUBLE: case DOUBLE: preparedState.setDouble(index, isNull ? 0 : Double.parseDouble(param.getValue())); break; case PRIMITIVE_BOOLEAN: case BOOLEAN: preparedState.setBoolean(index, !isNull && Boolean.parseBoolean(param.getValue())); break; case PRIMITIVE_BYTE: case BYTE: preparedState.setByte(index, isNull ? 0 : Byte.parseByte(param.getValue())); break; case JAVA_UTIL_DATE: case JAVA_SQL_DATE: preparedState.setDate(index, isNull ? null : java.sql.Date.valueOf(param.getValue())); break; case JAVA_SQL_TIME: preparedState.setTime(index, isNull ? null : Time.valueOf(param.getValue())); break; case JAVA_SQL_TIMESTAMP: preparedState.setTimestamp(index, isNull ? null : Timestamp.valueOf(param.getValue())); break; default: preparedState.setObject(index, isNull ? null : param.getValue()); } }
Example 6
Source File: DashboardService.java From kylin with Apache License 2.0 | 4 votes |
private PrepareSqlRequest createPrepareSqlRequest(String[] dimensions, String[] metrics, String category, Map<String, String> filterMap) { PrepareSqlRequest sqlRequest = new PrepareSqlRequest(); sqlRequest.setProject(MetricsManager.SYSTEM_PROJECT); StringBuffer baseSQL = new StringBuffer("select "); StringBuffer groupBy = new StringBuffer(""); if (dimensions != null && dimensions.length > 0) { groupBy.append(" group by "); StringBuffer dimensionSQL = new StringBuffer(""); for (String dimension : dimensions) { dimensionSQL.append(","); dimensionSQL.append(dimension); } baseSQL.append(dimensionSQL.substring(1)); groupBy.append(dimensionSQL.substring(1)); } if (metrics != null && metrics.length > 0) { StringBuffer metricSQL = new StringBuffer(""); for (String metric : metrics) { metricSQL.append(","); metricSQL.append(metric); } if (groupBy.length() > 0) { baseSQL.append(metricSQL); } else { baseSQL.append(metricSQL.substring(1)); } } baseSQL.append(" from "); baseSQL.append(category); if (filterMap != null && filterMap.size() > 0) { PrepareSqlRequest.StateParam[] params = new PrepareSqlRequest.StateParam[filterMap.size()]; int i = 0; StringBuffer filterSQL = new StringBuffer(" where "); Iterator<String> it = filterMap.keySet().iterator(); String filter = it.next(); filterSQL.append(filter); params[i] = new PrepareSqlRequest.StateParam(); params[i].setClassName("java.lang.String"); params[i++].setValue(filterMap.get(filter)); while (it.hasNext()) { filter = it.next(); filterSQL.append(" and "); filterSQL.append(filter); params[i] = new PrepareSqlRequest.StateParam(); params[i].setClassName("java.lang.String"); params[i++].setValue(filterMap.get(filter)); } baseSQL.append(filterSQL.toString()); sqlRequest.setParams(params); } baseSQL.append(groupBy); sqlRequest.setSql(baseSQL.toString()); return sqlRequest; }
Example 7
Source File: QueryService.java From Kylin with Apache License 2.0 | 4 votes |
/** * @param preparedState * @param param * @throws SQLException */ private void setParam(PreparedStatement preparedState, int index, PrepareSqlRequest.StateParam param) throws SQLException { boolean isNull = (null == param.getValue()); Class<?> clazz; try { clazz = Class.forName(param.getClassName()); } catch (ClassNotFoundException e) { throw new RuntimeException(e.getMessage(), e); } Rep rep = Rep.of(clazz); switch (rep) { case PRIMITIVE_CHAR: case CHARACTER: case STRING: preparedState.setString(index, isNull ? null : String.valueOf(param.getValue())); break; case PRIMITIVE_INT: case INTEGER: preparedState.setInt(index, isNull ? 0 : Integer.valueOf(param.getValue())); break; case PRIMITIVE_SHORT: case SHORT: preparedState.setShort(index, isNull ? 0 : Short.valueOf(param.getValue())); break; case PRIMITIVE_LONG: case LONG: preparedState.setLong(index, isNull ? 0 : Long.valueOf(param.getValue())); break; case PRIMITIVE_FLOAT: case FLOAT: preparedState.setFloat(index, isNull ? 0 : Float.valueOf(param.getValue())); break; case PRIMITIVE_DOUBLE: case DOUBLE: preparedState.setDouble(index, isNull ? 0 : Double.valueOf(param.getValue())); break; case PRIMITIVE_BOOLEAN: case BOOLEAN: preparedState.setBoolean(index, !isNull && Boolean.parseBoolean(param.getValue())); break; case PRIMITIVE_BYTE: case BYTE: preparedState.setByte(index, isNull ? 0 : Byte.valueOf(param.getValue())); break; case JAVA_UTIL_DATE: case JAVA_SQL_DATE: preparedState.setDate(index, isNull ? null : java.sql.Date.valueOf(param.getValue())); break; case JAVA_SQL_TIME: preparedState.setTime(index, isNull ? null : Time.valueOf(param.getValue())); break; case JAVA_SQL_TIMESTAMP: preparedState.setTimestamp(index, isNull ? null : Timestamp.valueOf(param.getValue())); break; default: preparedState.setObject(index, isNull ? null : param.getValue()); } }