pinax-network / substreams-sink-sql

Apache License 2.0
0 stars 0 forks source link

Issue using `Nullable(String)` type #13

Closed DenisCarriere closed 3 months ago

DenisCarriere commented 3 months ago

Same issue with Nullable(String)

CREATE TABLE IF NOT EXISTS logs
(
    topic0              String,
    topic1              Nullable(String),
    topic2              Nullable(String),
    topic3              Nullable(String),

JSON with empty newValue

{
  "table": "logs",
  "operation": "OPERATION_CREATE",
  "fields": [
    {
      "name": "topic0",
      "newValue": "0xdbccb92686efceafb9bb7e0394df7f58f71b954061b81afb57109bf247d3d75a"
    },
    {
      "name": "topic1",
      "newValue": "0x0000000000000000000000000c0f71f46f1f8f6beb301cc55a7e7ba55e8604f3"
    },
    {
      "name": "topic2"
    },
    {
      "name": "topic3"
    },
    {
      "name": "tx_hash",
      "newValue": "0x85621a86874614a218da822ef990a9c543ee1b25c678269644e0df956ba7b9df"
    }
  ],
  "compositePk": {
    "keys": {
      "tx_hash": "0x85621a86874614a218da822ef990a9c543ee1b25c678269644e0df956ba7b9df"
    }
  }
}

❌ Error unsupported pointer type *string

2024-07-28T11:28:39.418+0200 ERRO (sink-sql) handle BlockScopedData message at block #1598910 (f83b4bd9b91d157f2f6d8c3ad90dd69c1b7c050f3a372dc0af792a2533c6b5fe): failed to flush at block #1598910 (f83b4bd9b91d157f2f6d8c3ad90dd69c1b7c050f3a372dc0af792a2533c6b5fe): dialect flush: failed to get values: converting value "0x00000000000000000000000012dbd4c669e3e860a6432dcb69c8ded6b77be616" to type "string" in column "topic1": unsupported pointer type string

JSON with no newValue

{
  "table": "logs",
  "operation": "OPERATION_CREATE",
  "fields": [
    {
      "name": "topic0",
      "newValue": "0xdbccb92686efceafb9bb7e0394df7f58f71b954061b81afb57109bf247d3d75a"
    },
    {
      "name": "tx_hash",
      "newValue": "0x85621a86874614a218da822ef990a9c543ee1b25c678269644e0df956ba7b9df"
    }
  ],
  "compositePk": {
    "keys": {
      "tx_hash": "0x85621a86874614a218da822ef990a9c543ee1b25c678269644e0df956ba7b9df"
    }
  }
}

❌ Error expected 5 arguments, got 2

ERRO (sink-sql) handle BlockScopedData message at block #1598910 (f83b4bd9b91d157f2f6d8c3ad90dd69c1b7c050f3a372dc0af792a2533c6b5fe): failed to flush at block #1598910 (f83b4bd9b91d157f2f6d8c3ad90dd69c1b7c050f3a372dc0af792a2533c6b5fe): dialect flush: executing for entry ["0xdbccb92686efceafb9bb7e0394df7f58f71b954061b81afb57109bf247d3d75a" "0x93cd12315159f1333d0c33cef4d1587b84a147320fbb13514e54121809ad2d17"]: clickhouse [Append]: clickhouse: expected 5 arguments, got 2

DenisCarriere commented 3 months ago

✅ FIXED

Fixed by setting all values as String and returning empty string as newValue

CREATE TABLE IF NOT EXISTS logs
(
    topic0              String,
    topic1              String,
    topic2              String,
    topic3              String,

Rust

pub fn extract_topic(topics: &Vec<Vec<u8>>, index: usize) -> String {
    if index < topics.len() {
        bytes_to_hex(topics[index].clone())
    } else {
        "".to_string()
    }
}

JSON

{
  "table": "logs",
  "operation": "OPERATION_CREATE",
  "fields": [
    {
      "name": "topic0",
      "newValue": "0xdbccb92686efceafb9bb7e0394df7f58f71b954061b81afb57109bf247d3d75a"
    },
    {
      "name": "topic1",
      "newValue": "0x0000000000000000000000000c0f71f46f1f8f6beb301cc55a7e7ba55e8604f3"
    },
    {
      "name": "topic2"
    },
    {
      "name": "topic3"
    },
    {
      "name": "tx_hash",
      "newValue": "0x85621a86874614a218da822ef990a9c543ee1b25c678269644e0df956ba7b9df"
    }
  ],
  "compositePk": {
    "keys": {
      "tx_hash": "0x85621a86874614a218da822ef990a9c543ee1b25c678269644e0df956ba7b9df"
    }
  }
}