All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.easy.query.clickhouse.func.ClickHouseLikeSQLFunction Maven / Gradle / Ivy

There is a newer version: 2.3.3
Show newest version
package com.easy.query.clickhouse.func;

import com.easy.query.core.enums.SQLLikeEnum;
import com.easy.query.core.expression.parser.core.available.TableAvailable;
import com.easy.query.core.func.column.ColumnExpression;
import com.easy.query.core.func.def.AbstractExpressionSQLFunction;

import java.util.List;

/**
 * create time 2024/3/11 20:50
 * 文件说明
 *
 * @author xuejiaming
 */
public class ClickHouseLikeSQLFunction extends AbstractExpressionSQLFunction {
    private final List columnExpressions;
    private final SQLLikeEnum sqlLikeEnum;

    public ClickHouseLikeSQLFunction(List columnExpressions, SQLLikeEnum sqlLikeEnum) {

        this.columnExpressions = columnExpressions;
        this.sqlLikeEnum = sqlLikeEnum;
    }

    @Override
    public String sqlSegment(TableAvailable defaultTable) {
        if (columnExpressions.size() != 2) {
            throw new IllegalArgumentException("bank arguments != 1");
        }
        if (sqlLikeEnum == SQLLikeEnum.LIKE_PERCENT_RIGHT) {
            return "positionCaseInsensitive({0}, {1}) = 1";
        }
        if (sqlLikeEnum == SQLLikeEnum.LIKE_PERCENT_LEFT) {
            return "{0} LIKE CONCAT('%', {1})";
        }
        return "positionCaseInsensitive({0}, {1}) > 0";
    }

    @Override
    public int paramMarks() {
        return columnExpressions.size();
    }

    @Override
    protected List getColumnExpressions() {
        return columnExpressions;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy