Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(map): Codegen for Avro IDL Target #75

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/codegen/fromcto/avro/avrovisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,22 @@ class AvroVisitor {
avroType = `union { null, ${avroType} }`;
}

if (ModelUtil.isMap(field)) {
const mapDeclaration = field.getModelFile().getType(field.getType());
let mapValueType = mapDeclaration.getValue().getType();

if (ModelUtil.isScalar(mapDeclaration.getValue())) {
const scalarDeclaration = mapDeclaration.getModelFile().getType(mapValueType);
mapValueType = scalarDeclaration.getType();
}

const avroValueType = this.toAvroType(mapValueType);

parameters.fileWriter.writeLine(2, `map<${avroValueType}> ${field.getName()};`); // key is always inferred to be string.

return null;
}

const fieldName = this.toAvroName(field.getName());

/**
Expand Down
36 changes: 18 additions & 18 deletions test/codegen/__snapshots__/codegen.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ protocol MyProtocol {
record Company {
string name;
Address headquarters;
union { null, CompanyProperties } companyProperties;
union { null, EmployeeDirectory } employeeDirectory;
union { null, EmployeeTShirtSizes } employeeTShirtSizes;
union { null, EmployeeProfiles } employeeProfiles;
union { null, EmployeeSocialSecurityNumbers } employeeSocialSecurityNumbers;
map<string> companyProperties;
map<Employee> employeeDirectory;
map<TShirtSizeType> employeeTShirtSizes;
map<Concept> employeeProfiles;
map<string> employeeSocialSecurityNumbers;
}

enum Department {
Expand Down Expand Up @@ -150,7 +150,7 @@ protocol MyProtocol {
double height;
@logicalType("timestamp-micros")
long dob;
NextOfKin nextOfKin;
map<string> nextOfKin;
}

record Employee {
Expand All @@ -171,7 +171,7 @@ protocol MyProtocol {
double height;
@logicalType("timestamp-micros")
long dob;
NextOfKin nextOfKin;
map<string> nextOfKin;
}

record Contractor {
Expand All @@ -186,7 +186,7 @@ protocol MyProtocol {
double height;
@logicalType("timestamp-micros")
long dob;
NextOfKin nextOfKin;
map<string> nextOfKin;
}

record Manager {
Expand All @@ -208,7 +208,7 @@ protocol MyProtocol {
double height;
@logicalType("timestamp-micros")
long dob;
NextOfKin nextOfKin;
map<string> nextOfKin;
}

record CompanyEvent {
Expand Down Expand Up @@ -6012,11 +6012,11 @@ protocol MyProtocol {
record Company {
string name;
Address headquarters;
union { null, CompanyProperties } companyProperties;
union { null, EmployeeDirectory } employeeDirectory;
union { null, EmployeeTShirtSizes } employeeTShirtSizes;
union { null, EmployeeProfiles } employeeProfiles;
union { null, EmployeeSocialSecurityNumbers } employeeSocialSecurityNumbers;
map<string> companyProperties;
map<Employee> employeeDirectory;
map<TShirtSizeType> employeeTShirtSizes;
map<Concept> employeeProfiles;
map<string> employeeSocialSecurityNumbers;
}

enum Department {
Expand Down Expand Up @@ -6052,7 +6052,7 @@ protocol MyProtocol {
double height;
@logicalType("timestamp-micros")
long dob;
NextOfKin nextOfKin;
map<string> nextOfKin;
}

record Employee {
Expand All @@ -6073,7 +6073,7 @@ protocol MyProtocol {
double height;
@logicalType("timestamp-micros")
long dob;
NextOfKin nextOfKin;
map<string> nextOfKin;
}

record Contractor {
Expand All @@ -6088,7 +6088,7 @@ protocol MyProtocol {
double height;
@logicalType("timestamp-micros")
long dob;
NextOfKin nextOfKin;
map<string> nextOfKin;
}

record Manager {
Expand All @@ -6110,7 +6110,7 @@ protocol MyProtocol {
double height;
@logicalType("timestamp-micros")
long dob;
NextOfKin nextOfKin;
map<string> nextOfKin;
}

record CompanyEvent {
Expand Down
Loading