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批量插入失败 #1882

Open
wangboshun opened this issue Sep 10, 2024 · 5 comments
Open

clickhouse批量插入失败 #1882

wangboshun opened this issue Sep 10, 2024 · 5 comments

Comments

@wangboshun
Copy link
Contributor

wangboshun commented Sep 10, 2024

在使用最新版的clickhouse.client驱动7.7.3时,使用批量删除失败。
通过跟踪源代码发现是因为freesql转换的DataTable的字段顺序和clickhouse.client不一样导致的。

这个原因请问该如何解决?

freesql InsertProvider文件的ToDataTable方法
image

clickhouse.client ClickHouseBulkCopy文件的LoadNamesAndTypesAsync 方法
image
image

clickhouse.client ClickHouseBulkCopy文件的SerializeBatch
image
image

问题描述及重现代码:

  _fsql.Insert(list).NoneParameter().ExecuteAffrows();


实体如下 
[Table(Name = "sys_api_log")]
public class ApiLogEntity
{
 
    [Column(IsPrimary = true, Name = "id", CanUpdate = false)]
    public string Id { set; get; }

 
    [Column(Name = "ct", ServerTime = DateTimeKind.Local, CanUpdate = false)]
    [JsonProperty("ct")]
    public DateTime CreateTime { set; get; }

 
    [Column(Name = "uid")]
    [JsonProperty("uid")]
    public string UserId { set; get; }

    /// <summary>
    ///     url
    /// </summary>
    [Column(Name = "url")]
    [JsonProperty("url")]
    public string? Url { set; get; }
 
    [Column(Name = "ip")]
    [JsonProperty("ip")]
    public string IP { set; get; }
 
    [Column(Name = "body")]
    [JsonProperty("body")]
    public string Body { set; get; }

    [Column(Name = "take_time")]
    [JsonProperty("take_time")]
    public int TakeTime { get; set; }
 
    [Column(Name = "code")]
    [JsonProperty("code")]
    public int Code { get; set; }
}

数据库版本

clickhouse 23

安装的Nuget包

3.2.833

.net framework/. net core? 及具体版本

.net 8

@2881099
Copy link
Collaborator

2881099 commented Sep 10, 2024

实体类的属性顺序改一下,或者设置他们的 Position

@wangboshun
Copy link
Contributor Author

实体类的属性顺序改一下,或者设置他们的 Position

有没有啥更智能的方法,因为好多类我都需要一个个的对比顺序,太麻烦了

@2881099
Copy link
Collaborator

2881099 commented Sep 10, 2024

clickhouse.client支持传入columnNames吗

@wangboshun
Copy link
Contributor Author

clickhouse.client支持传入columnNames吗

貌似不支持

@2881099
Copy link
Collaborator

2881099 commented Sep 10, 2024

程序启动查询数据库信息,fluent api 批量设置 Column Position 值

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

2 participants