Java Code Examples for org.apache.kylin.metadata.project.ProjectInstance#getConfig()

The following examples show how to use org.apache.kylin.metadata.project.ProjectInstance#getConfig() . 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: TableDesc.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public KylinConfig getConfig() {
    if (project == null) {
        return config;
    } else {
        ProjectInstance projInstance = ProjectManager.getInstance(config).getProject(project);
        return projInstance == null ? config : projInstance.getConfig();
    }
}
 
Example 2
Source File: QueryUtil.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
public static String massagePushDownSql(String sql, String project, String defaultSchema, boolean isPrepare) {
    ProjectManager projectManager = ProjectManager.getInstance(KylinConfig.getInstanceFromEnv());
    ProjectInstance projectInstance = projectManager.getProject(project);
    KylinConfig kylinConfig = projectInstance.getConfig();
    while (sql.endsWith(";"))
        sql = sql.substring(0, sql.length() - 1);

    return massagePushDownSql(kylinConfig, sql, project, defaultSchema, isPrepare);
}
 
Example 3
Source File: TableDesc.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
public KylinConfig getConfig() {
    if (project == null) {
        return config;
    } else {
        ProjectInstance projInstance = ProjectManager.getInstance(config).getProject(project);
        return projInstance == null ? config : projInstance.getConfig();
    }
}
 
Example 4
Source File: QueryUtil.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
/**
 * @deprecated Deprecated because of KYLIN-3594
 */
@Deprecated
public static String massageSql(String sql, String project, int limit, int offset, String defaultSchema) {
    sql = sql.trim();
    sql = sql.replace("\r", " ").replace("\n", System.getProperty("line.separator"));

    ProjectManager projectManager = ProjectManager.getInstance(KylinConfig.getInstanceFromEnv());
    ProjectInstance projectInstance = projectManager.getProject(project);
    KylinConfig kylinConfig = projectInstance.getConfig();
    sql = removeCommentInSql(sql);
    while (sql.endsWith(";"))
        sql = sql.substring(0, sql.length() - 1);

    String sql1 = sql;
    final String suffixPattern = "^.+?\\s(limit\\s\\d+)?\\s(offset\\s\\d+)?\\s*$";
    sql = sql.replaceAll("\\s+", " ");
    Pattern pattern = Pattern.compile(suffixPattern);
    Matcher matcher = pattern.matcher(sql.toLowerCase(Locale.ROOT) + "  ");

    int toAppendLimit = 0;
    int toAppendOffset = 0;
    if (matcher.find()) {
        if (limit > 0 && matcher.group(1) == null) {
            toAppendLimit = limit;
        }
        if (offset > 0 && matcher.group(2) == null) {
            toAppendOffset = offset;
        }
    }

    // https://issues.apache.org/jira/browse/KYLIN-2649
    if (kylinConfig.getForceLimit() > 0 && limit <= 0 && matcher.group(1) == null
            && sql1.toLowerCase(Locale.ROOT).matches("^select\\s+\\*\\p{all}*")) {
        toAppendLimit = kylinConfig.getForceLimit();
    }

    sql1 = appendLimitOffsetToSql(sql1, toAppendLimit, toAppendOffset);

    // customizable SQL transformation
    if (queryTransformers == null) {
        initQueryTransformers();
    }
    for (IQueryTransformer t : queryTransformers) {
        sql1 = t.transform(sql1, project, defaultSchema);
    }
    return sql1;
}
 
Example 5
Source File: QueryUtil.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
public static String massageSql(String sql, String project, int limit, int offset, String defaultSchema, boolean isCCNeeded) {
    ProjectManager projectManager = ProjectManager.getInstance(KylinConfig.getInstanceFromEnv());
    ProjectInstance projectInstance = projectManager.getProject(project);
    KylinConfig kylinConfig = projectInstance.getConfig();
    return massageSql(kylinConfig, sql, project, limit, offset, defaultSchema, isCCNeeded);
}
 
Example 6
Source File: QueryUtil.java    From kylin with Apache License 2.0 4 votes vote down vote up
/**
 * @deprecated Deprecated because of KYLIN-3594
 */
@Deprecated
public static String massageSql(String sql, String project, int limit, int offset, String defaultSchema) {
    sql = sql.trim();
    sql = sql.replace("\r", " ").replace("\n", System.getProperty("line.separator"));

    ProjectManager projectManager = ProjectManager.getInstance(KylinConfig.getInstanceFromEnv());
    ProjectInstance projectInstance = projectManager.getProject(project);
    KylinConfig kylinConfig = projectInstance.getConfig();
    sql = removeCommentInSql(sql);
    while (sql.endsWith(";"))
        sql = sql.substring(0, sql.length() - 1);

    String sql1 = sql;
    final String suffixPattern = "^.+?\\s(limit\\s\\d+)?\\s(offset\\s\\d+)?\\s*$";
    sql = sql.replaceAll("\\s+", " ");
    Pattern pattern = Pattern.compile(suffixPattern);
    Matcher matcher = pattern.matcher(sql.toLowerCase(Locale.ROOT) + "  ");

    int toAppendLimit = 0;
    int toAppendOffset = 0;
    if (matcher.find()) {
        if (limit > 0 && matcher.group(1) == null) {
            toAppendLimit = limit;
        }
        if (offset > 0 && matcher.group(2) == null) {
            toAppendOffset = offset;
        }
    }

    // https://issues.apache.org/jira/browse/KYLIN-2649
    if (kylinConfig.getForceLimit() > 0 && limit <= 0 && matcher.group(1) == null
            && sql1.toLowerCase(Locale.ROOT).matches("^select\\s+\\*\\p{all}*")) {
        toAppendLimit = kylinConfig.getForceLimit();
    }

    sql1 = appendLimitOffsetToSql(sql1, toAppendLimit, toAppendOffset);

    // customizable SQL transformation
    if (queryTransformers == null) {
        initQueryTransformers();
    }
    for (IQueryTransformer t : queryTransformers) {
        sql1 = t.transform(sql1, project, defaultSchema);
    }
    return sql1;
}