37 lines
1.4 KiB
Java
37 lines
1.4 KiB
Java
import club.kingon.sql.builder.SqlBuilder;
|
|
import club.kingon.sql.builder.entry.Alias;
|
|
import club.kingon.sql.builder.entry.Column;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.db.sql.SqlFormatter;
|
|
import org.eclipse.collections.api.factory.Lists;
|
|
|
|
import static com.eshore.odcp.hudi.connector.Constants.DATABASE_NAME;
|
|
|
|
/**
|
|
* @author lanyuanxiaoyao
|
|
* @date 2023-06-07
|
|
*/
|
|
public class SqlBuilderTests {
|
|
private static final Alias TABLE_VERSION = Alias.of(StrUtil.format("{}.tb_app_collect_table_version", DATABASE_NAME), "tactv");
|
|
private static final Alias TABLE_INFO = Alias.of(StrUtil.format("{}.tb_app_collect_table_info", DATABASE_NAME), "tacti");
|
|
|
|
private static String column(Alias table, String column) {
|
|
return StrUtil.format("{}.{}", table.getAlias(), column);
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
System.out.println(SqlFormatter.format(
|
|
SqlBuilder
|
|
.select("count(*)")
|
|
.from(TABLE_INFO)
|
|
.join(TABLE_VERSION)
|
|
.onEq(column(TABLE_INFO, "flink_job_id"), Column.as(column(TABLE_VERSION, "flink_job_id")))
|
|
.andEq(column(TABLE_INFO, "alias"), Column.as(column(TABLE_VERSION, "alias")))
|
|
.whereEq(false, "a", "b")
|
|
.andEq("b", "c")
|
|
.andIn("d", Lists.immutable.empty())
|
|
.build()
|
|
));
|
|
}
|
|
}
|