Skip to content

Commit

Permalink
[UOD-1887] add eos.type property to primitive avro types (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
romain-gilles-ultra authored Jan 10, 2024
1 parent da951dd commit 2e8d6e2
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 114 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"Structs",
"trxs",
"Undecodable",
"varuint",
"zlog",
"zstd"
]
Expand Down
15 changes: 10 additions & 5 deletions avro.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,15 @@ func NewOptional(schema Schema) Union {
func NewTimestampMillisField(name string) FieldSchema {
return FieldSchema{
Name: name,
Type: NewTimestampMillisType(),
Type: NewTimestampMillisType("block_timestamp_type"),
}
}

func NewTimestampMillisType() Schema {
return map[string]string{
func NewTimestampMillisType(eosType string) Schema {
return map[string]interface{}{
"type": "long",
"logicalType": "timestamp-millis",
"eos.type": eosType,
}
}

Expand All @@ -169,6 +170,7 @@ func NewInt128Type() Schema {
"precision": 39,
"scale": 0,
"convert": "eos.Int128",
"eos.type": "int128",
}
}

Expand All @@ -178,6 +180,7 @@ func NewUint64Type() Schema {
"logicalType": "decimal",
"precision": 20,
"scale": 0,
"eos.type": "uint64",
}
}

Expand All @@ -188,6 +191,7 @@ func NewUint128Type() Schema {
"precision": 39,
"scale": 0,
"convert": "eos.Uint128",
"eos.type": "uint128",
}
}

Expand All @@ -200,7 +204,8 @@ func NewIntField(name string) FieldSchema {

func NewSymbolType() Schema {
return map[string]interface{}{
"type": "string",
"convert": "eos.Symbol",
"type": "string",
"convert": "eos.Symbol",
"eos.type": "symbol",
}
}
46 changes: 23 additions & 23 deletions schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,32 +469,32 @@ var avroRecordTypeByBuiltInTypes map[string]RecordSchema

func initBuiltInTypesForTables() {
avroPrimitiveTypeByBuiltInTypes = map[string]interface{}{
"bool": "boolean",
"int8": "int",
"uint8": "int",
"int16": "int",
"uint16": "int",
"int32": "int",
"uint32": "long",
"int64": "long",
"uint64": "long", // FIXME maybe use Decimal here see goavro or FIXED
"bool": map[string]interface{}{"type": "boolean", "eos.type": "bool"},
"int8": map[string]interface{}{"type": "int", "eos.type": "int8"},
"uint8": map[string]interface{}{"type": "int", "eos.type": "uint8"},
"int16": map[string]interface{}{"type": "int", "eos.type": "int16"},
"uint16": map[string]interface{}{"type": "int", "eos.type": "uint16"},
"int32": map[string]interface{}{"type": "int", "eos.type": "int32"},
"uint32": map[string]interface{}{"type": "long", "eos.type": "uint32"},
"int64": map[string]interface{}{"type": "long", "eos.type": "int64"},
"uint64": map[string]interface{}{"type": "long", "eos.type": "uint64"}, // FIXME maybe use Decimal here see goavro or FIXED
"int128": NewInt128Type(),
"uint128": NewUint128Type(),
"varint32": "int",
"varuint32": "long",
"float32": "float",
"float64": "double",
"time_point": NewTimestampMillisType(), // fork/eos-go/abidecoder.go TODO add ABI.nativeTime bool to skip time to string conversion in abidecoder read method
"time_point_sec": NewTimestampMillisType(), // fork/eos-go/abidecoder.go
"block_timestamp_type": NewTimestampMillisType(), // fork/eos-go/abidecoder.go
"name": "string",
"bytes": "bytes",
"string": "string",
"checksum160": "bytes",
"checksum256": "bytes",
"checksum512": "bytes",
"varint32": map[string]interface{}{"type": "int", "eos.type": "varint32"},
"varuint32": map[string]interface{}{"type": "long", "eos.type": "varuint32"},
"float32": map[string]interface{}{"type": "float", "eos.type": "float32"},
"float64": map[string]interface{}{"type": "double", "eos.type": "float64"},
"time_point": NewTimestampMillisType("time_point"), // fork/eos-go/abidecoder.go TODO add ABI.nativeTime bool to skip time to string conversion in abidecoder read method
"time_point_sec": NewTimestampMillisType("time_point_sec"), // fork/eos-go/abidecoder.go
"block_timestamp_type": NewTimestampMillisType("block_timestamp_type"), // fork/eos-go/abidecoder.go
"name": map[string]interface{}{"type": "string", "eos.type": "name"},
"bytes": map[string]interface{}{"type": "bytes", "eos.type": "bytes"},
"string": map[string]interface{}{"type": "string", "eos.type": "string"},
"checksum160": map[string]interface{}{"type": "bytes", "eos.type": "checksum160"},
"checksum256": map[string]interface{}{"type": "bytes", "eos.type": "checksum256"},
"checksum512": map[string]interface{}{"type": "bytes", "eos.type": "checksum512"},
"symbol": NewSymbolType(),
"symbol_code": "string", // FIXME check with blockchain team
"symbol_code": map[string]interface{}{"type": "string", "eos.type": "symbol_code"}, // FIXME check with blockchain team
}
avroRecordTypeByBuiltInTypes = map[string]RecordSchema{
"asset": assetSchema,
Expand Down
Loading

0 comments on commit 2e8d6e2

Please sign in to comment.