-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use an index lookup for O(1) field index access
- Loading branch information
Showing
2 changed files
with
77 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
|
||
// Licensed to the Apache Software Foundation (ASF) under one or more | ||
// contributor license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright ownership. | ||
// The ASF licenses this file to You under the Apache License, Version 2.0 | ||
// (the "License"); you may not use this file except in compliance with | ||
// the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using Apache.Arrow; | ||
using Apache.Arrow.Types; | ||
using System; | ||
using Xunit; | ||
|
||
namespace Apache.Arrow.Tests; | ||
|
||
internal class SchemaTests | ||
{ | ||
public class Construct | ||
{ | ||
[Fact] | ||
public void ThrowsWhenFieldsAreNull() | ||
{ | ||
Assert.Throws<ArgumentNullException>(() => new Schema(null, null)); | ||
Assert.Throws<ArgumentNullException>(() => new Schema(null, null, copyCollections: false)); | ||
} | ||
} | ||
|
||
public class IndexRetrieval | ||
{ | ||
[Fact] | ||
public void CanRetrieveFieldIndexByName() | ||
{ | ||
var field0 = new Field("f0", Int32Type.Default, true); | ||
var field1 = new Field("f1", Int64Type.Default, true); | ||
var schema = new Schema([field0, field1], null); | ||
|
||
Assert.Equal(0, schema.GetFieldIndex("f0")); | ||
Assert.Equal(1, schema.GetFieldIndex("f1")); | ||
Assert.Equal(-1, schema.GetFieldIndex("nonexistent")); | ||
} | ||
|
||
[Fact] | ||
public void CanRetrieveFieldIndexByNonUniqueName() | ||
{ | ||
var field0 = new Field("f0", Int32Type.Default, true); | ||
var field1 = new Field("f1", Int64Type.Default, true); | ||
|
||
// Repeat fields in the list | ||
var schema = new Schema([field0, field1, field0, field1], null); | ||
|
||
Assert.Equal(0, schema.GetFieldIndex("f0")); | ||
Assert.Equal(1, schema.GetFieldIndex("f1")); | ||
Assert.Equal(-1, schema.GetFieldIndex("nonexistent")); | ||
} | ||
} | ||
} |