Creating a Table
Function Description
In the following example, the on cluster statement is used to create distributed and local tables on all Server nodes in the cluster.
createSql is used to create a local table, and createDisSql is used to create a distributed table based on the local table.
Sample Code
private void createTable(String databaseName, String tableName, String clusterName) throws Exception { String createSql = "create table " + databaseName + "." + tableName + " on cluster " + clusterName + " (name String, age UInt8, date Date)engine=ReplicatedMergeTree('/clickhouse/tables/{shard}/" + databaseName + "." + tableName + "'," + "'{replica}') partition by toYYYYMM(date) order by age"; String createDisSql = "create table " + databaseName + "." + tableName + "_all" + " on cluster " + clusterName + " as " + databaseName + "." + tableName + " ENGINE = Distributed(default_cluster," + databaseName + "," + tableName + ", rand());"; ArrayList<String> sqlList = new ArrayList<String>(); sqlList.add(createSql); sqlList.add(createDisSql); util.exeSql(sqlList); }
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot