Skip to content

Commit

Permalink
add logical types
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiabasone committed Aug 12, 2024
1 parent 724c2f9 commit de3f4dc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Objects/Schema/Generation/TypeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ public function __construct(SchemaGenerator $generator)
TypeName::MAP => $this->simpleType(Schema::map()),
TypeName::ENUM => $this->simpleType(Schema::enum()),
TypeName::FIXED => $this->simpleType(Schema::fixed()),
TypeName::UUID => $this->simpleType(Schema::uuid()),
TypeName::TIME_MICROS => $this->simpleType(Schema::timeMicros()),
TypeName::TIME_MILLIS => $this->simpleType(Schema::timeMillis()),
TypeName::TIMESTAMP_MICROS => $this->simpleType(Schema::timestampMicros()),
TypeName::TIMESTAMP_MILLIS => $this->simpleType(Schema::timestampMillis()),
TypeName::LOCAL_TIMESTAMP_MICROS => $this->simpleType(Schema::localTimestampMicros()),
TypeName::LOCAL_TIMESTAMP_MILLIS => $this->simpleType(Schema::localTimestampMillis()),
];
}

Expand Down
12 changes: 12 additions & 0 deletions test/Objects/Schema/Generation/Fixture/SimpleRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,16 @@ class SimpleRecord
#[AvroType("int")]
#[AvroDefault(42)]
private $intType;

/**
* @SerDe\AvroType("uuid")
*/
#[AvroType("uuid")]
private $uuidType;

/**
* @SerDe\AvroType("timestamp-millis")
*/
#[AvroType("timestamp-millis")]
private $timestampMillisType;
}
15 changes: 15 additions & 0 deletions test/Objects/Schema/Generation/SchemaGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ public function it_should_generate_records_containing_records()
'intType',
Schema::int(),
FieldOption::default(42)
)
->field(
'uuidType',
Schema::uuid()
)
->field(
'timestampMillisType',
Schema::timestampMillis()
),
)
->field(
Expand Down Expand Up @@ -186,6 +194,13 @@ public function test_it_should_generate_records_containing_records_using_attribu
'intType',
Schema::int(),
FieldOption::default(42)
)->field(
'uuidType',
Schema::uuid()
)
->field(
'timestampMillisType',
Schema::timestampMillis()
),
)
->field(
Expand Down

0 comments on commit de3f4dc

Please sign in to comment.