Skip to content

Commit

Permalink
Change dictionary id assignment to conform to Java integration test e…
Browse files Browse the repository at this point in the history
…xpectations.

Support dictionaries in C data interface integration testing.
  • Loading branch information
CurtHagenlocher committed Dec 9, 2023
1 parent 8ac6a76 commit fd67722
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
4 changes: 2 additions & 2 deletions csharp/src/Apache.Arrow/Ipc/ArrowStreamWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ private protected virtual void FinishedWritingDictionary(long bodyLength, long m
private protected void WriteDictionaries(DictionaryMemo dictionaryMemo)
{
int fieldCount = dictionaryMemo?.DictionaryCount ?? 0;
for (int i = 1; i <= fieldCount; i++)
for (int i = 0; i < fieldCount; i++)
{
WriteDictionary(i, dictionaryMemo.GetDictionaryType(i), dictionaryMemo.GetDictionary(i));
}
Expand All @@ -526,7 +526,7 @@ private protected void WriteDictionary(long id, IArrowType valueType, IArrowArra
private protected async Task WriteDictionariesAsync(DictionaryMemo dictionaryMemo, CancellationToken cancellationToken)
{
int fieldCount = dictionaryMemo?.DictionaryCount ?? 0;
for (int i = 1; i <= fieldCount; i++)
for (int i = 0; i < fieldCount; i++)
{
await WriteDictionaryAsync(i, dictionaryMemo.GetDictionaryType(i), dictionaryMemo.GetDictionary(i), cancellationToken).ConfigureAwait(false);
}
Expand Down
2 changes: 1 addition & 1 deletion csharp/src/Apache.Arrow/Ipc/DictionaryMemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public long GetOrAssignId(Field field)
{
if (!_fieldToId.TryGetValue(field, out long id))
{
id = _fieldToId.Count + 1;
id = _fieldToId.Count;
AddField(id, field);
}
return id;
Expand Down
25 changes: 16 additions & 9 deletions csharp/test/Apache.Arrow.IntegrationTest/JsonFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ public Schema GetSchemaAndDictionaries(out Func<DictionaryType, IArrowArray> dic
return schema;
}

/// <summary>
/// Return both the schema and a specific batch number.
/// This method is used by C Data Interface integration testing.
/// </summary>
public Schema ToArrow(int batchNumber, out RecordBatch batch)
{
Schema schema = Schema.ToArrow(out Dictionary<DictionaryType, int> dictionaryIndexes);

Func<DictionaryType, IArrowArray> lookup = null;
lookup = type => Dictionaries.Single(d => d.Id == dictionaryIndexes[type]).Data.ToArrow(type.ValueType, lookup);

batch = Batches[batchNumber].ToArrow(schema, lookup);

return schema;
}

private static JsonSerializerOptions GetJsonOptions()
{
JsonSerializerOptions options = new JsonSerializerOptions()
Expand Down Expand Up @@ -366,15 +382,6 @@ public RecordBatch ToArrow(Schema schema, Func<DictionaryType, IArrowArray> dict
return CreateRecordBatch(schema, dictionaries, this);
}

/// <summary>
/// Decode this JSON record batch as a RecordBatch instance without supporting dictionaries.
/// This method is used by C Data Interface integration testing.
/// </summary>
public RecordBatch ToArrow(Schema schema)
{
return CreateRecordBatch(schema, _ => throw new NotImplementedException(), this);
}

public IArrowArray ToArrow(IArrowType arrowType, Func<DictionaryType, IArrowArray> dictionaries)
{
ArrayCreator creator = new ArrayCreator(this.Columns[0], dictionaries);
Expand Down
4 changes: 1 addition & 3 deletions dev/archery/archery/integration/tester_csharp.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ def _pointer_to_int(self, c_ptr):
def _read_batch_from_json(self, json_path, num_batch):
from Apache.Arrow.IntegrationTest import CDataInterface

jf = CDataInterface.ParseJsonFile(json_path)
schema = jf.Schema.ToArrow()
return schema, jf.Batches[num_batch].ToArrow(schema)
return CDataInterface.ParseJsonFile(json_path).ToArrow(num_batch)

def _run_gc(self):
from Apache.Arrow.IntegrationTest import CDataInterface
Expand Down

0 comments on commit fd67722

Please sign in to comment.