GithubHelp home page GithubHelp logo

Comments (5)

killwort avatar killwort commented on July 25, 2024

Nope, query parser in driver does not support such syntax.
By the way, you have control over parameter type/value, why do you need explicit cast?
And, as clickhouse documentation states, you shouldn't use one-row inserts, check info in https://github.com/killwort/ClickHouse-Net#hidden-bulk-insert-functionality here for more efficient way of inserting.

from clickhouse-net.

RomanOlegovich avatar RomanOlegovich commented on July 25, 2024

@killwort
I want to import rows from Postgres

select OrderId, IsFirstOrder from orders

and export to ClickHouse

insert into FactOrder (OrderId, IsFirstOrder) values @bulk

Both database has boolean db type for IsFirstOrder.

But in c# code IsFirstOrder has different db types: Boolean in postgres and DbByte in clickhouse.

System.InvalidCastException: 'Unable to cast object of type 'System.Boolean' to type 'System.SByte'.'

Read from Postgres

                using (var dataReader = cmd.ExecuteReader())
                {
                    while (dataReader.Read())
                    {
                        var row = new Dictionary<string, object>();
                        for (var fieldCount = 0; fieldCount < dataReader.FieldCount; fieldCount++)
                        {
                            row.Add(dataReader.GetName(fieldCount), dataReader[fieldCount]);
                        }
                        yield return row;
                    }
                }

write to ClickHouse

            using (var cmd = db.CreateCommand())
            {
                cmd.CommandText = sql;
                if (cmd.Connection.State != ConnectionState.Open) { cmd.Connection.Open(); }

                if (@params != null)
                    foreach (KeyValuePair<string, object> p in @params)
                    {
                        IDbDataParameter dbParameter = cmd.CreateParameter();
                        dbParameter.ParameterName = p.Key;
                        dbParameter.Value = p.Value;
                        cmd.Parameters.Add(dbParameter);
                    }

                return cmd.ExecuteNonQuery();
            }

How I can cast postgres:boolean to clickhouse:boolean in this case?

from clickhouse-net.

killwort avatar killwort commented on July 25, 2024

When you implement IEnumerable interface in your object, do casts on return, like that:

  class MyDataObject:IEnumerable{
    public bool SomeBooleanFieldStoredInUInt8{get;set;}
    ....
    public IEnumerator GetEnumerator(){
      ....
      yield return SomeBooleanFieldStoredInUInt8?(byte)1:(byte)0;
      ....
    }
  }

from clickhouse-net.

RomanOlegovich avatar RomanOlegovich commented on July 25, 2024

the idea is that all the code should be in sql, and c # does not know what data will be there, c # code can only call DbCommand for reading and writing.

from clickhouse-net.

RomanOlegovich avatar RomanOlegovich commented on July 25, 2024

I think it may be a part of your sdk.
DBNull -> (object)null
Bool => sbyte

from clickhouse-net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.