lidavidm commented on issue #581:
URL: https://github.com/apache/arrow-adbc/issues/581#issuecomment-1501381444

   Yes, decltype would work. I think the hard part there will be that SQLite 
doesn't really check the type name so we would have to replicate 3.1.1 here: 
https://www.sqlite.org/datatype3.html
   
   Also it looks that decltype will fail if it's something like `x + 1` so in 
that case the user might still get a type that is a little unexpected. 
   
   On Mon, Apr 10, 2023, at 10:10, Sutou Kouhei wrote:
   > 
   > 
   > Ah, I thought that `sqlite3_column_type()` can work with an empty table. 
So I thought that we can improve the current implementation by:
   > 
   > diff --git a/c/driver/sqlite/statement_reader.c 
b/c/driver/sqlite/statement_reader.c
   > index 694b8cc..21fb20f 100644
   > --- a/c/driver/sqlite/statement_reader.c
   > +++ b/c/driver/sqlite/statement_reader.c
   > @@ -495,7 +495,7 @@ void StatementReaderRelease(struct ArrowArrayStream* 
self) {
   >  
   >  /// Initialize buffers for the first (type-inferred) batch of data.
   >  /// Use raw buffers since the types may change.
   > -AdbcStatusCode StatementReaderInitializeInfer(int num_columns, size_t 
infer_rows,
   > +AdbcStatusCode StatementReaderInitializeInfer(sqlite3_stmt *stmt, int 
num_columns, size_t infer_rows,
   >                                                struct ArrowBitmap* 
validity,
   >                                                struct ArrowBuffer* data,
   >                                                struct ArrowBuffer* binary,
   > @@ -507,7 +507,21 @@ AdbcStatusCode StatementReaderInitializeInfer(int 
num_columns, size_t infer_rows
   >      ArrowBufferInit(&data[i]);
   >      CHECK_NA(INTERNAL, ArrowBufferReserve(&data[i], infer_rows * 
sizeof(int64_t)), error);
   >      memset(&binary[i], 0, sizeof(struct ArrowBuffer));
   > -    current_type[i] = NANOARROW_TYPE_INT64;
   > +    int sqlite_type = sqlite3_column_type(stmt, i);
   > +    switch (sqlite_type) {
   > +    case SQLITE_FLOAT:
   > +      current_type[i] = NANOARROW_TYPE_DOUBLE;
   > +      break;
   > +    case SQLITE_TEXT:
   > +      current_type[i] = NANOARROW_TYPE_STRING;
   > +      break;
   > +    case SQLITE_BLOB:
   > +      current_type[i] = NANOARROW_TYPE_BINARY;
   > +      break;
   > +    default:
   > +      current_type[i] = NANOARROW_TYPE_INT64;
   > +      break;
   > +    }
   >    }
   >    return ADBC_STATUS_OK;
   >  }  // NOLINT(whitespace/indent)
   > @@ -835,7 +849,7 @@ AdbcStatusCode AdbcSqliteExportReader(sqlite3* db, 
sqlite3_stmt* stmt,
   >    enum ArrowType* current_type = malloc(num_columns * sizeof(enum 
ArrowType));
   >  
   >    AdbcStatusCode status = StatementReaderInitializeInfer(
   > -      num_columns, batch_size, validity, data, binary, current_type, 
error);
   > +      stmt, num_columns, batch_size, validity, data, binary, 
current_type, error);
   >    if (status == ADBC_STATUS_OK) {
   >      int64_t num_rows = 0;
   >      while (num_rows < batch_size) {
   > But `sqlite3_column_type()` always returns `SQLITE_NULL` with the case. :<
   > 
   > We may want to use `sqlite3_column_decltype()`...
   > 
   > 
   > 
   > —
   > Reply to this email directly, view it on GitHub 
<https://github.com/apache/arrow-adbc/issues/581#issuecomment-1501267541>, or 
unsubscribe 
<https://github.com/notifications/unsubscribe-auth/AACQB36Y4GKADDJHBM6LKXLXANMXJANCNFSM6AAAAAAWYK5JDU>.
   > You are receiving this because you commented.Message ID: ***@***.***>
   > 
   > 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to