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

com.easy.query.clickhouse.func.ClickHouseDateTimePropertySQLFunction 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.expression.parser.core.available.TableAvailable;
import com.easy.query.core.func.column.ColumnExpression;
import com.easy.query.core.func.def.AbstractExpressionSQLFunction;
import com.easy.query.core.func.def.enums.DateTimeUnitEnum;
import com.easy.query.core.util.EasyCollectionUtil;

import java.util.List;

/**
 * create time 2023/12/21 11:58
 * 文件说明
 *
 * @author xuejiaming
 */
public class ClickHouseDateTimePropertySQLFunction extends AbstractExpressionSQLFunction {
    private final List columnExpressions;
    private final DateTimeUnitEnum dateTimeUnitEnum;

    public ClickHouseDateTimePropertySQLFunction(List columnExpressions, DateTimeUnitEnum dateTimeUnitEnum) {

        this.columnExpressions = columnExpressions;
        this.dateTimeUnitEnum = dateTimeUnitEnum;
    }

    @Override
    public String sqlSegment(TableAvailable defaultTable) {
        if(EasyCollectionUtil.isEmpty(columnExpressions)){
            throw new IllegalArgumentException("columnExpressions is empty");
        }
        switch (dateTimeUnitEnum){
            case DayOfYear:return "toDayOfYear({0})";
            case DayOfWeek:return "(toDayOfWeek({0})-1)";
            case Year:return "toYear({0})";
            case Month:return "toMonth({0})";
            case Day:return "toDayOfMonth({0})";
            case Hour:return "toHour({0})";
            case Minute:return "toMinute({0})";
            case Second:return "toSecond({0})";
        }
        throw new UnsupportedOperationException("不支持当前属性获取:"+ dateTimeUnitEnum);
    }

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

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

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy