Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClickHouse PARTITION BY support in CodeFirst CREATE TABLE #1814

Open
wizzard0 opened this issue May 29, 2024 · 3 comments
Open

ClickHouse PARTITION BY support in CodeFirst CREATE TABLE #1814

wizzard0 opened this issue May 29, 2024 · 3 comments

Comments

@wizzard0
Copy link

For large clickhouse tables, partition key is essential. Currently there's no way to specify partition key (usually a function from the timestamp primary key column, like toYYYYMM(time)), and looking at the clickhouse provider there's no code that could insert the PARTITION BY clause in CREATE TABLE statement builder either.

Since the partition can be an arbitrary function, this calls for a new property in the TableAttribute, not ColumnAttribute

Thanks in advance!

@d4ilys
Copy link
Contributor

d4ilys commented May 30, 2024

    public class Table
    {
        [Column(IsPrimary = true, IsIdentity = true)]
        public int Id { get; set; }
		
        public string Name { get; set; }

        [ClickHousePartition("toYYYYMM({0})")]   //partition attribute , toYYYYMM({0}) is string format
        [Column(Name = "create_time")]
        public DateTime CreateTime { get; set; }
    }
CREATE TABLE IF NOT EXISTS `Table` (  
  `Id` Int32, 
  `Name` Nullable(String), 
  `create_time` DateTime('Asia/Shanghai'), 
   PRIMARY KEY ( `Id` ) 
) 
ENGINE = MergeTree() 
ORDER BY ( `Id` )  
PARTITION BY toYYYYMM(`create_time`)    -- table partition
SETTINGS index_granularity = 8192

Does this design meet your needs, or do you have any good suggestions

@2881099
Copy link
Collaborator

2881099 commented May 30, 2024

FreeSql.Provider.ClickHouse 3.2.826-preview20240530

@wizzard0
Copy link
Author

wizzard0 commented Jun 4, 2024

Missed the email, sorry! Yes this meets the needs. Thanks! Also the FreeSql currently doesn't properly handle Array(Int64) columns while the underlying Clickhouse.Client works OK, but I'll create a separate issue for that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants