You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "sgilmore10 (via GitHub)" <gi...@apache.org> on 2023/11/01 20:28:13 UTC
[PR] GH-38417: [MATLAB] Implement a `TableTypeValidator` class that validates a MATLAB `cell` array contains only `table`s that share the same schema [arrow]
sgilmore10 opened a new pull request, #38551:
URL: https://github.com/apache/arrow/pull/38551
### Rationale for this change
This is a followup to #38533.
Adding this `TableValidator` class is a step towards implementing the `arrow.array.ListArray.fromMATLAB` method for creating `ListArray`s whose `ValueType` is a `StructArray`.
This validator will ensure all `table`s in a `cell` array have the same schema when attempting to make a `ListArray` of `Struct`s. This is a requirement to ensure the `table`s in the `cell` array are vertcat'ble. For example, two `table`s with different `VariableNames` cannot be concatenated together:
```matlab
>> t1 = table(1, 2, VariableNames=["A", "B"]);
>> t2 = table(3, 4, VariableNames=["C", "D"]);
>> vertcat(t1, t2)
Error using tabular/vertcat
All tables being vertically concatenated must have the same variable names.
```
### What changes are included in this PR?
1. Modified `arrow.array.internal.list.Validator` to inherit from `matlab.mixin.Heterogeneous`. Doing so enables creating an array whose elements are different subclasses of `arrow.array.internal.list.Validator`.
2. Added a new MATLAB class `arrow.array.internal.list.TableValidator`, which inherits from `arrow.array.internal.list.Validator`. This class has two properties: `VariableNames` and `VariableValidators`. `VariableNames` is a `string` array containing the variable names all `table`s are expected to have. `VariableValidators` is an array of `arrow.array.internal.list.Validator`, where each element represents one variable in a `table`. This array is used to validate `table` variables have the expected type and configuration. `TableValidator`'s `validateElement method uses both of these properties to ensure the input provided is a `table` with the correct schema.
3. Added a gateway function called `arrow.array.internal.list.createValidator`, which creates the appropriate `Validator` subclass based on the input. If no such `Validator` exists, this function throws an error.
### Are these changes tested?
Yes. Added two new test classes: `tTableValidator.m` and `tCreateValidator.m`.
### Are there any user-facing changes?
No.
### Future Directions:
1. #38354
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-38417: [MATLAB] Implement a `TableTypeValidator` class that validates a MATLAB `cell` array contains only `table`s that share the same schema [arrow]
Posted by "kevingurney (via GitHub)" <gi...@apache.org>.
kevingurney commented on code in PR #38551:
URL: https://github.com/apache/arrow/pull/38551#discussion_r1380642415
##########
matlab/src/matlab/+arrow/+array/+internal/+list/TableValidator.m:
##########
@@ -0,0 +1,90 @@
+% 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.
+
+classdef TableValidator < arrow.array.internal.list.ClassTypeValidator
+
+ properties (GetAccess=public, SetAccess=private)
+ VariableNames string = string.empty(1, 0)
+ VariableValidators arrow.array.internal.list.Validator = arrow.array.internal.list.Validator.empty(1, 0)
+ end
+
+ methods
+ function obj = TableValidator(T)
+ arguments
+ T table {}
Review Comment:
I think you can remove the `{}`
##########
matlab/src/matlab/+arrow/+array/+internal/+list/TableValidator.m:
##########
@@ -0,0 +1,90 @@
+% 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.
+
+classdef TableValidator < arrow.array.internal.list.ClassTypeValidator
+
+ properties (GetAccess=public, SetAccess=private)
+ VariableNames string = string.empty(1, 0)
+ VariableValidators arrow.array.internal.list.Validator = arrow.array.internal.list.Validator.empty(1, 0)
+ end
+
+ methods
+ function obj = TableValidator(T)
+ arguments
+ T table {}
+ end
+
+ numVars = width(T);
+
+ if (numVars == 0)
+ error("arrow:array:list:TableWithZeroVariables", ...
+ "Expect tables to have at least one variable.");
+ end
+
+ obj@arrow.array.internal.list.ClassTypeValidator(table);
+ obj.VariableNames = string(T.Properties.VariableNames);
+ validators = cell([1 numVars]);
+ for ii = 1:numVars
+ validators{ii} = arrow.array.internal.list.createValidator(T.(ii));
+ end
+
+ obj.VariableValidators = [validators{:}];
+ end
+
+ function validateElement(obj, element)
+ % Verify element is a table
+ validateElement@arrow.array.internal.list.ClassTypeValidator(obj, element);
+
+ % Validate element has the expected number of variables
+ numVars = numel(obj.VariableNames);
+ if width(element) ~= numVars
+ id = "arrow:array:list:NumVariablesMismatch";
+ msg = "Expect all tables in the cell array to have " + ...
Review Comment:
```suggestion
msg = "Expected all tables in the cell array to have " + ...
```
##########
matlab/src/matlab/+arrow/+array/+internal/+list/TableValidator.m:
##########
@@ -0,0 +1,90 @@
+% 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.
+
+classdef TableValidator < arrow.array.internal.list.ClassTypeValidator
+
+ properties (GetAccess=public, SetAccess=private)
+ VariableNames string = string.empty(1, 0)
+ VariableValidators arrow.array.internal.list.Validator = arrow.array.internal.list.Validator.empty(1, 0)
+ end
+
+ methods
+ function obj = TableValidator(T)
+ arguments
+ T table {}
+ end
+
+ numVars = width(T);
+
+ if (numVars == 0)
+ error("arrow:array:list:TableWithZeroVariables", ...
+ "Expect tables to have at least one variable.");
Review Comment:
```suggestion
"Expected table to have at least one variable.");
```
##########
matlab/test/arrow/array/list/tTableValidator.m:
##########
@@ -0,0 +1,283 @@
+%TTABLEVALIDATOR Unit tests for arrow.array.internal.list.TableValidator
+
+% 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.
+
+classdef tTableValidator < matlab.unittest.TestCase
+
+ properties (Constant)
+ BaseTable = table(1, "A", datetime(2023, 11, 1, TimeZone="UTC"), ...
+ VariableNames=["Number", "Letter", "Date"]);
+ end
+
+ methods(Test)
+ function Smoke(testCase)
+ import arrow.array.internal.list.TableValidator
+
+ validator = TableValidator(testCase.BaseTable);
+ testCase.verifyInstanceOf(validator, "arrow.array.internal.list.TableValidator");
+ end
+
+ function TableWithZeroVariablesError(testCase)
+ % Verify the TableValidator constructor throws an exception
+ % whose identifier is "arrow:array:list:TableWithZeroVariables"
+ % if provided a table with zero variables.
+ import arrow.array.internal.list.TableValidator
+
+ fcn = @() TableValidator(table);
+ testCase.verifyError(fcn, "arrow:array:list:TableWithZeroVariables");
+ end
+
+ function VariableNamesGetter(testCase)
+ % Verify the VariableNames property getter returns the
+ % expected string array.
+ import arrow.array.internal.list.TableValidator
+
+ validator = TableValidator(testCase.BaseTable);
+ testCase.verifyEqual(validator.VariableNames, ["Number", "Letter", "Date"]);
+ end
+
+ function VariableNamesNoSetter(testCase)
+ % Verify the VariableNames property is not settable.
+ import arrow.array.internal.list.TableValidator
+
+ validator = TableValidator(testCase.BaseTable);
+ fcn = @() setfield(validator, "VariableNames", ["A", "B", "C"]);
+ testCase.verifyError(fcn, "MATLAB:class:SetProhibited");
+ end
+
+ function VariableValidatorsGetter(testCase)
+ % Verify the VariableValidators getter returns the expected
+ % arrow.array.internal.list.Validator array.
+
+ import arrow.array.internal.list.TableValidator
+ import arrow.array.internal.list.DatetimeValidator
+ import arrow.array.internal.list.ClassTypeValidator
+
+ validator = TableValidator(testCase.BaseTable);
+
+ numberVariableValidator = ClassTypeValidator(1);
+ letterVariableValidator = ClassTypeValidator("A");
+ datetimeVariableValidator = DatetimeValidator(datetime(2023, 10, 31, TimeZone="UTC"));
+ expectedValidators = [numberVariableValidator letterVariableValidator datetimeVariableValidator];
+ testCase.verifyEqual(validator.VariableValidators, expectedValidators);
+ end
+
+ function VariableValidatorsNoSetter(testCase)
+ % Verify the VariableValidators property is not settable.
+ import arrow.array.internal.list.TableValidator
+ import arrow.array.internal.list.ClassTypeValidator
+
+ validator = TableValidator(testCase.BaseTable);
+ numberVariableValidator = ClassTypeValidator(1);
+ fcn = @() setfield(validator, "VariableValidators", numberVariableValidator);
+ testCase.verifyError(fcn, "MATLAB:class:SetProhibited");
+ end
+
+ function ClassNameGetter(testCase)
+ % Verify the ClassName getter returns the expected scalar
+ % string.
+ import arrow.array.internal.list.TableValidator
+
+ validator = TableValidator(testCase.BaseTable);
+ testCase.verifyEqual(validator.ClassName, "table");
+ end
+
+ function ClassNameNoSetter(testCase)
+ % Verify the ClassName property is not settable.
+ import arrow.array.internal.list.TableValidator
+
+ validator = TableValidator(testCase.BaseTable);
+ fcn = @() setfield(validator, "ClassName", "string");
+ testCase.verifyError(fcn, "MATLAB:class:SetProhibited");
+ end
+
+ function ValidateElementClassTypeMismatchError(testCase)
+ % Verify validateElement throws an exception whose identifier
+ % is "arrow:array:list:ClassTypeMismatch" if the input is
+ % not a table.
+ import arrow.array.internal.list.TableValidator
+
+ validator = TableValidator(testCase.BaseTable);
+ errorID = "arrow:array:list:ClassTypeMismatch";
+ fcn = @() validator.validateElement(1);
+ testCase.verifyError(fcn, errorID);
+ fcn = @() validator.validateElement(seconds(1));
+ testCase.verifyError(fcn, errorID);
+ end
+
+ function ValidateElementNumVariablesMismatchError(testCase)
+ % Verify validateElement throws an exception whose identifier
+ % is "arrow:array:list:NumVariablesMismatch" if the input table
+ % does not have the expected number of variables.
+ import arrow.array.internal.list.TableValidator
+
+ validator = TableValidator(testCase.BaseTable);
+ errorID = "arrow:array:list:NumVariablesMismatch";
+
+ inputTable = table(1, "A", VariableNames=["Number", "Letter"]);
+ fcn = @() validator.validateElement(inputTable);
+ testCase.verifyError(fcn, errorID);
+
+ inputTable = table(1, "A", datetime(2023, 10, 30, TimeZone="UTC"), seconds(1), ...
+ VariableNames=["Number", "Letter", "Date", "Time"]);
+ fcn = @() validator.validateElement(inputTable);
+ testCase.verifyError(fcn, errorID);
+ end
+
+ function ValidateElementVariableNamesMismatchError(testCase)
+ % Verify validateElement throws an exception whose identifier
+ % is "arrow:array:list:NumVariablesMismatch" if the input table
+ % does not have the expected variable names of variables.
+ import arrow.array.internal.list.TableValidator
+
+ validator = TableValidator(testCase.BaseTable);
+ errorID = "arrow:array:list:VariableNamesMismatch";
+
+ inputTable = table(1, "A", datetime(2023, 10, 31, TimeZone="UTC"), ...
+ VariableNames=["A", "B", "C"]);
+ fcn = @() validator.validateElement(inputTable);
+ testCase.verifyError(fcn, errorID);
+ end
+
+ function ValidateElementErrorFromFirstVariable(testCase)
+ % Verify validateElement throws an exception if there is an
+ % issue with the first variable in the input table.
+ import arrow.array.internal.list.TableValidator
+
+ validator = TableValidator(testCase.BaseTable);
+
+ % validator expects the second variable to be a double
+ inputTable = table(true, "A", datetime(2023, 10, 31, TimeZone="UTC"), ...
+ VariableNames=["Number", "Letter", "Date"]);
+ fcn = @() validator.validateElement(inputTable);
+ testCase.verifyError(fcn, "arrow:array:list:ClassTypeMismatch");
+
+ % validator expects all table variables that are not tables
+ % themselves to be columnar or empty
+ inputTable = table([1 2 3 4], "B", datetime(2023, 10, 31, TimeZone="UTC"), ...
Review Comment:
```suggestion
notColumnar = [1 2 3 4];
inputTable = table(notColumnar, "B", datetime(2023, 10, 31, TimeZone="UTC"), ...
```
##########
matlab/src/matlab/+arrow/+array/+internal/+list/TableValidator.m:
##########
@@ -0,0 +1,90 @@
+% 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.
+
+classdef TableValidator < arrow.array.internal.list.ClassTypeValidator
+
+ properties (GetAccess=public, SetAccess=private)
+ VariableNames string = string.empty(1, 0)
+ VariableValidators arrow.array.internal.list.Validator = arrow.array.internal.list.Validator.empty(1, 0)
+ end
+
+ methods
+ function obj = TableValidator(T)
+ arguments
+ T table {}
+ end
+
+ numVars = width(T);
+
+ if (numVars == 0)
+ error("arrow:array:list:TableWithZeroVariables", ...
+ "Expect tables to have at least one variable.");
+ end
+
+ obj@arrow.array.internal.list.ClassTypeValidator(table);
+ obj.VariableNames = string(T.Properties.VariableNames);
+ validators = cell([1 numVars]);
+ for ii = 1:numVars
+ validators{ii} = arrow.array.internal.list.createValidator(T.(ii));
+ end
+
+ obj.VariableValidators = [validators{:}];
+ end
+
+ function validateElement(obj, element)
+ % Verify element is a table
+ validateElement@arrow.array.internal.list.ClassTypeValidator(obj, element);
+
+ % Validate element has the expected number of variables
+ numVars = numel(obj.VariableNames);
+ if width(element) ~= numVars
+ id = "arrow:array:list:NumVariablesMismatch";
+ msg = "Expect all tables in the cell array to have " + ...
+ string(numVars) + " variables.";
+ error(id, msg);
+ end
+
+ % Validate element has the expected variable names
+ if ~all(obj.VariableNames == string(element.Properties.VariableNames))
+ id = "arrow:array:list:VariableNamesMismatch";
+ msg = "Expect all tables in the cell array to have the " + ...
Review Comment:
```suggestion
msg = "Expected all tables in the cell array to have the " + ...
```
##########
matlab/src/matlab/+arrow/+array/+internal/+list/TableValidator.m:
##########
@@ -0,0 +1,90 @@
+% 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.
+
+classdef TableValidator < arrow.array.internal.list.ClassTypeValidator
+
+ properties (GetAccess=public, SetAccess=private)
+ VariableNames string = string.empty(1, 0)
+ VariableValidators arrow.array.internal.list.Validator = arrow.array.internal.list.Validator.empty(1, 0)
+ end
+
+ methods
+ function obj = TableValidator(T)
+ arguments
+ T table {}
+ end
+
+ numVars = width(T);
+
+ if (numVars == 0)
+ error("arrow:array:list:TableWithZeroVariables", ...
+ "Expect tables to have at least one variable.");
+ end
+
+ obj@arrow.array.internal.list.ClassTypeValidator(table);
+ obj.VariableNames = string(T.Properties.VariableNames);
+ validators = cell([1 numVars]);
+ for ii = 1:numVars
+ validators{ii} = arrow.array.internal.list.createValidator(T.(ii));
+ end
+
+ obj.VariableValidators = [validators{:}];
+ end
+
+ function validateElement(obj, element)
+ % Verify element is a table
+ validateElement@arrow.array.internal.list.ClassTypeValidator(obj, element);
+
+ % Validate element has the expected number of variables
+ numVars = numel(obj.VariableNames);
+ if width(element) ~= numVars
+ id = "arrow:array:list:NumVariablesMismatch";
+ msg = "Expect all tables in the cell array to have " + ...
+ string(numVars) + " variables.";
+ error(id, msg);
+ end
+
+ % Validate element has the expected variable names
+ if ~all(obj.VariableNames == string(element.Properties.VariableNames))
+ id = "arrow:array:list:VariableNamesMismatch";
+ msg = "Expect all tables in the cell array to have the " + ...
+ "same variable names.";
+ error(id, msg);
+ end
+
+ for ii=1:numVars
+ var = element.(ii);
+
+ % In order to concatenate tables together later, require
+ % all non-tabular variables to be columnar or empty.
+ if ~istable(var) && (~iscolumn(var) && ~isempty(var))
+ id = "arrow:array:list:NonTabularVariablesMustBeColumnar";
+ msg = "Expect all variables except for nested tables to be columnar.";
Review Comment:
```suggestion
msg = "Expected all variables except for nested tables to be columnar.";
```
##########
matlab/test/arrow/array/list/tTableValidator.m:
##########
@@ -0,0 +1,283 @@
+%TTABLEVALIDATOR Unit tests for arrow.array.internal.list.TableValidator
+
+% 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.
+
+classdef tTableValidator < matlab.unittest.TestCase
+
+ properties (Constant)
+ BaseTable = table(1, "A", datetime(2023, 11, 1, TimeZone="UTC"), ...
+ VariableNames=["Number", "Letter", "Date"]);
+ end
+
+ methods(Test)
+ function Smoke(testCase)
+ import arrow.array.internal.list.TableValidator
+
+ validator = TableValidator(testCase.BaseTable);
+ testCase.verifyInstanceOf(validator, "arrow.array.internal.list.TableValidator");
+ end
+
+ function TableWithZeroVariablesError(testCase)
+ % Verify the TableValidator constructor throws an exception
+ % whose identifier is "arrow:array:list:TableWithZeroVariables"
+ % if provided a table with zero variables.
+ import arrow.array.internal.list.TableValidator
+
+ fcn = @() TableValidator(table);
+ testCase.verifyError(fcn, "arrow:array:list:TableWithZeroVariables");
+ end
+
+ function VariableNamesGetter(testCase)
+ % Verify the VariableNames property getter returns the
+ % expected string array.
+ import arrow.array.internal.list.TableValidator
+
+ validator = TableValidator(testCase.BaseTable);
+ testCase.verifyEqual(validator.VariableNames, ["Number", "Letter", "Date"]);
+ end
+
+ function VariableNamesNoSetter(testCase)
+ % Verify the VariableNames property is not settable.
+ import arrow.array.internal.list.TableValidator
+
+ validator = TableValidator(testCase.BaseTable);
+ fcn = @() setfield(validator, "VariableNames", ["A", "B", "C"]);
+ testCase.verifyError(fcn, "MATLAB:class:SetProhibited");
+ end
+
+ function VariableValidatorsGetter(testCase)
+ % Verify the VariableValidators getter returns the expected
+ % arrow.array.internal.list.Validator array.
+
+ import arrow.array.internal.list.TableValidator
+ import arrow.array.internal.list.DatetimeValidator
+ import arrow.array.internal.list.ClassTypeValidator
+
+ validator = TableValidator(testCase.BaseTable);
+
+ numberVariableValidator = ClassTypeValidator(1);
+ letterVariableValidator = ClassTypeValidator("A");
+ datetimeVariableValidator = DatetimeValidator(datetime(2023, 10, 31, TimeZone="UTC"));
+ expectedValidators = [numberVariableValidator letterVariableValidator datetimeVariableValidator];
+ testCase.verifyEqual(validator.VariableValidators, expectedValidators);
+ end
+
+ function VariableValidatorsNoSetter(testCase)
+ % Verify the VariableValidators property is not settable.
+ import arrow.array.internal.list.TableValidator
+ import arrow.array.internal.list.ClassTypeValidator
+
+ validator = TableValidator(testCase.BaseTable);
+ numberVariableValidator = ClassTypeValidator(1);
+ fcn = @() setfield(validator, "VariableValidators", numberVariableValidator);
+ testCase.verifyError(fcn, "MATLAB:class:SetProhibited");
+ end
+
+ function ClassNameGetter(testCase)
+ % Verify the ClassName getter returns the expected scalar
+ % string.
+ import arrow.array.internal.list.TableValidator
+
+ validator = TableValidator(testCase.BaseTable);
+ testCase.verifyEqual(validator.ClassName, "table");
+ end
+
+ function ClassNameNoSetter(testCase)
+ % Verify the ClassName property is not settable.
+ import arrow.array.internal.list.TableValidator
+
+ validator = TableValidator(testCase.BaseTable);
+ fcn = @() setfield(validator, "ClassName", "string");
+ testCase.verifyError(fcn, "MATLAB:class:SetProhibited");
+ end
+
+ function ValidateElementClassTypeMismatchError(testCase)
+ % Verify validateElement throws an exception whose identifier
+ % is "arrow:array:list:ClassTypeMismatch" if the input is
+ % not a table.
+ import arrow.array.internal.list.TableValidator
+
+ validator = TableValidator(testCase.BaseTable);
+ errorID = "arrow:array:list:ClassTypeMismatch";
+ fcn = @() validator.validateElement(1);
+ testCase.verifyError(fcn, errorID);
+ fcn = @() validator.validateElement(seconds(1));
+ testCase.verifyError(fcn, errorID);
+ end
+
+ function ValidateElementNumVariablesMismatchError(testCase)
+ % Verify validateElement throws an exception whose identifier
+ % is "arrow:array:list:NumVariablesMismatch" if the input table
+ % does not have the expected number of variables.
+ import arrow.array.internal.list.TableValidator
+
+ validator = TableValidator(testCase.BaseTable);
+ errorID = "arrow:array:list:NumVariablesMismatch";
+
+ inputTable = table(1, "A", VariableNames=["Number", "Letter"]);
+ fcn = @() validator.validateElement(inputTable);
+ testCase.verifyError(fcn, errorID);
+
+ inputTable = table(1, "A", datetime(2023, 10, 30, TimeZone="UTC"), seconds(1), ...
+ VariableNames=["Number", "Letter", "Date", "Time"]);
+ fcn = @() validator.validateElement(inputTable);
+ testCase.verifyError(fcn, errorID);
+ end
+
+ function ValidateElementVariableNamesMismatchError(testCase)
+ % Verify validateElement throws an exception whose identifier
+ % is "arrow:array:list:NumVariablesMismatch" if the input table
+ % does not have the expected variable names of variables.
+ import arrow.array.internal.list.TableValidator
+
+ validator = TableValidator(testCase.BaseTable);
+ errorID = "arrow:array:list:VariableNamesMismatch";
+
+ inputTable = table(1, "A", datetime(2023, 10, 31, TimeZone="UTC"), ...
+ VariableNames=["A", "B", "C"]);
+ fcn = @() validator.validateElement(inputTable);
+ testCase.verifyError(fcn, errorID);
+ end
+
+ function ValidateElementErrorFromFirstVariable(testCase)
+ % Verify validateElement throws an exception if there is an
+ % issue with the first variable in the input table.
+ import arrow.array.internal.list.TableValidator
+
+ validator = TableValidator(testCase.BaseTable);
+
+ % validator expects the second variable to be a double
+ inputTable = table(true, "A", datetime(2023, 10, 31, TimeZone="UTC"), ...
+ VariableNames=["Number", "Letter", "Date"]);
+ fcn = @() validator.validateElement(inputTable);
+ testCase.verifyError(fcn, "arrow:array:list:ClassTypeMismatch");
+
+ % validator expects all table variables that are not tables
+ % themselves to be columnar or empty
+ inputTable = table([1 2 3 4], "B", datetime(2023, 10, 31, TimeZone="UTC"), ...
+ VariableNames=["Number", "Letter", "Date"]);
+ fcn = @() validator.validateElement(inputTable);
+ testCase.verifyError(fcn, "arrow:array:list:NonTabularVariablesMustBeColumnar");
+ end
+
+ function ValidateElementErrorFromSecondVariable(testCase)
+ % Verify validateElement throws an exception if there is an
+ % issue with the second variable in the input table.
+ import arrow.array.internal.list.TableValidator
+
+ validator = TableValidator(testCase.BaseTable);
+
+ % validator expects the second variable to be a string
+ inputTable = table(2, seconds(1), datetime(2023, 10, 31, TimeZone="UTC"), ...
+ VariableNames=["Number", "Letter", "Date"]);
+ fcn = @() validator.validateElement(inputTable);
+ testCase.verifyError(fcn, "arrow:array:list:ClassTypeMismatch");
+
+ % validator expects all table variables that are not tables
+ % themselves to be columnar or empty
+ inputTable = table(2, ["A" "B"], datetime(2023, 10, 31, TimeZone="UTC"), ...
+ VariableNames=["Number", "Letter", "Date"]);
+ fcn = @() validator.validateElement(inputTable);
+ testCase.verifyError(fcn, "arrow:array:list:NonTabularVariablesMustBeColumnar");
+ end
+
+ function ValidateElementErrorFromThirdVariable(testCase)
+ % Verify validateElement throws an exception if there is an
+ % issue with the third variable in the input table.
+ import arrow.array.internal.list.TableValidator
+
+ validator = TableValidator(testCase.BaseTable);
+
+ % validator expects the third variable to be a zoned datetime
+ inputTable = table(2, "B", datetime(2023, 10, 31), ...
+ VariableNames=["Number", "Letter", "Date"]);
+ fcn = @() validator.validateElement(inputTable);
+ testCase.verifyError(fcn, "arrow:array:list:ExpectedZonedDatetime");
+
+ % validator expects the third variable to be datetime
+ inputTable = table(2, "B", uint8(1), ...
+ VariableNames=["Number", "Letter", "Date"]);
+ fcn = @() validator.validateElement(inputTable);
+ testCase.verifyError(fcn, "arrow:array:list:ClassTypeMismatch");
+
+ % validator expects all table variables that are not tables
+ % themselves to be columnar or empty
+ inputTable = table(2, "B", datetime(2023, 10, 31, TimeZone="UTC") + days(0:4), ...
+ VariableNames=["Number", "Letter", "Date"]);
+ fcn = @() validator.validateElement(inputTable);
+ testCase.verifyError(fcn, "arrow:array:list:NonTabularVariablesMustBeColumnar");
+ end
+
+ function validateElementNoThrow(testCase)
+ % Verify validateElement does not throw an exception if the
+ % input provided matches the expected schema.
+
+ import arrow.array.internal.list.TableValidator
+ validator = TableValidator(testCase.BaseTable);
+
+ inputTable = table(2, "B", datetime(2023, 10, 31, TimeZone="UTC"), ...
+ VariableNames=["Number", "Letter", "Date"]);
+ validator.validateElement(inputTable);
+
+ inputTable = repmat(inputTable, [10 1]);
+ validator.validateElement(inputTable);
+
+ inputTable = inputTable(1:0, :);
Review Comment:
Could you add a comment explaining what `1:0` is doing?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-38417: [MATLAB] Implement a `TableTypeValidator` class that validates a MATLAB `cell` array contains only `table`s that share the same schema [arrow]
Posted by "conbench-apache-arrow[bot] (via GitHub)" <gi...@apache.org>.
conbench-apache-arrow[bot] commented on PR #38551:
URL: https://github.com/apache/arrow/pull/38551#issuecomment-1791832903
After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit 56edb2d0f6b4a4a1689f5dbac9df1bb9a5274f2e.
There were no benchmark performance regressions. 🎉
The [full Conbench report](https://github.com/apache/arrow/runs/18324189350) has more details.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-38417: [MATLAB] Implement a `TableTypeValidator` class that validates a MATLAB `cell` array contains only `table`s that share the same schema [arrow]
Posted by "kevingurney (via GitHub)" <gi...@apache.org>.
kevingurney merged PR #38551:
URL: https://github.com/apache/arrow/pull/38551
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-38417: [MATLAB] Implement a `TableTypeValidator` class that validates a MATLAB `cell` array contains only `table`s that share the same schema [arrow]
Posted by "kevingurney (via GitHub)" <gi...@apache.org>.
kevingurney commented on PR #38551:
URL: https://github.com/apache/arrow/pull/38551#issuecomment-1791416061
+1
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org