package com.purui.prims.headless.core.executor;

import com.purui.prims.common.util.ContextUtils;
import com.purui.prims.headless.api.pojo.response.SemanticQueryResp;
import com.purui.prims.headless.core.pojo.Database;
import com.purui.prims.headless.core.pojo.QueryStatement;
import com.purui.prims.headless.core.utils.SqlUtils;
import lombok.extern.slf4j.Slf4j;

/**
 * Doris加速器
 *
 * @author charlie
 * @date 2024/6/25
 */
@Slf4j
public class DorisAccelerator extends AbstractAccelerator {
    @Override
    public boolean reload() {
        return false;
    }

    /**
     * 指标或数据集发布后，自动加速
     *
     * @param queryStatement
     * @return
     */
    @Override
    public boolean check(QueryStatement queryStatement) {
        return false;
    }

    @Override
    public SemanticQueryResp query(QueryStatement queryStatement) {
        SqlUtils sqlUtils = ContextUtils.getBean(SqlUtils.class);
        Database database = queryStatement.getSemanticModel().getDatabase();
        SemanticQueryResp queryResp = new SemanticQueryResp();
        SqlUtils sqlUtil = sqlUtils.init(database);
        sqlUtil.queryInternal(queryStatement.getSql(), queryResp);
        queryResp.setSql(queryStatement.getSql());
        return queryResp;
    }
}
