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

ChoParquetRecordFieldConfiguration not being applied correctly on file write #300

Open
jsn-m opened this issue Sep 27, 2023 · 0 comments
Open

Comments

@jsn-m
Copy link

jsn-m commented Sep 27, 2023

Hi,

I'm using reflection to write a IEnumerable<POCO> to Parquet. In setting up data types for each property, I can see on debug that the writerInstance that calls the Write method has a correct List<ChoParquetRecordConfiguration> object (Nullable Integers, etc).
However when the Write method is called, all Nullable types that are Numeric are just written as Strings. Don't know if reflection is getting in the way.

Example of code:

Type dtoType = GetDtoType(initReqBodyData.PathRoot, initReqBodyData.PathName); // returns Type Root.Sales.Data.SalesItem
dynamic restResponseDto = JsonConvert.DeserializeObject(restResponse.Content, typeof(IList<>).MakeGenericType(dtoType));

IEnumerable<PropertyInfo> dtoProperties = dtoType.GetAllProperties();
Dictionary<string, Type> fieldsAndTypes = SetFieldTypes(dtoProperties);

Type genericParquetWriter = typeof(ChoParquetWriter<>).MakeGenericType(dtoType);
dynamic writerInstance = ChoActivator.CreateInstance(genericParquetWriter, new object[] { localPath, new ChoParquetRecordConfiguration()
        {
            TypeConverterFormatSpec = new ChoTypeConverterFormatSpec { EnumFormat = ChoEnumFormatSpec.Name },
            TreatDateTimeAsString = false,
            CultureName = "en-001",
            AutoDiscoverFieldTypes = false,
            CompressionLevel = CompressionLevel.Fastest,
            CompressionMethod = Parquet.CompressionMethod.Snappy,
            Append = File.Exists(localPath),
            FieldValueTrimOption = ChoFieldValueTrimOption.Trim,
        }
    }
);

foreach(string propertyName in dtoProperties.Select(c => c.Name)) 
{                             
    writerInstance.WithField(propertyName, fieldType: fieldsAndTypes[propertyName]);      
}

writerInstance.Write(restResponseDto);
writerInstance.Close();
writerInstance.Dispose();

Example of JSON:

	{
		"salesItemId": "<guid>",
		"tenantId": "<guid>",
		"parentSalesItemId": null,
		"salesId": "<guid>",
		"productId": "<guid>",
		"groupId": null,
		"bundleId": null,
		"description": "Test",
		"linePrice": 110.0,
		"quantity": 1,
		"detailAmount": null // Example of Null Decimal
		"taxRate": 0.95,
		"taxAmount": 6.53,
		"unitServiceFee": 12.0,
		"serviceFeeDetailAmount": 15.0,
		"serviceTaxRate": 1.25,
		"isRevenue": false,
		"groupEnum": "None",
		"modifiedDate": "2020-01-01T00:00:00.100000",
		"isDeleted": false,
		"serviceFeeTaxAmount": 13.0,
		"derivativeSalesList": [],
		"salesItemList": [],
		"salesList": null
	}

From the above, the detailAmount is a Nullable Double in the ChoParquetRecordConfiguration but when I examine the column in the Parquet file it's a VARCHAR / String.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant