Consider the following valid Ballerina program that maps two identical data structures to CSV with io:fileWriteCsv:
import ballerina/io;
type Base record {|
int base1;
int base2;
|};
type Derived1 record {|
*Base;
int derived1;
int derived2;
|};
type Derived2 record {|
int base1;
int base2;
int derived1;
int derived2;
|};
public function main() returns error? {
Derived1[] d1 = [{ base1: 1, base2: 2, derived1: 3, derived2: 4 }];
Derived2[] d2 = [{ base1: 1, base2: 2, derived1: 3, derived2: 4 }];
check io:fileWriteCsv("derived1.csv", d1);
check io:fileWriteCsv("derived2.csv", d2);
}
I'm expecting the content of the both output CSV files to be identical to:
1,2,3,4
But instead I'm getting:
$ cat derived1.csv
3,4,1,2
$ cat derived2.csv
1,2,3,4
I'm surprised that type inclusion changes the order of the columns in CSV file. Is this a bug or by-design? If by-design what are the column ordering rules?
I'm using:
$ bal --version
Ballerina 2201.2.0 (Swan Lake Update 2)
Language specification 2022R3
Update Tool 1.3.10