Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions matlab/src/matlab/+arrow/+array/+internal/+display/getHeader.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@
% implied. See the License for the specific language governing
% permissions and limitations under the License.

function header = getHeader(className, numElements, numNulls)
function header = getHeader(fullClassName, numElements, numNulls)
import arrow.internal.display.pluralizeStringIfNeeded
elementString = pluralizeStringIfNeeded(numElements, "element");
import arrow.internal.display.getClassNameForDisplay
import arrow.internal.display.getNumString

className = getClassNameForDisplay(fullClassName);
elementString = pluralizeStringIfNeeded(numElements, "element");
nullString = pluralizeStringIfNeeded(numNulls, "null value");

numString = "%d";
if usejava("desktop")
% Bold the number of elements and nulls if the desktop is enabled
numString = compose("<strong>%s</strong>", numString);
end

formatSpec = " %s with " + numString + " %s and " + numString + " %s";
numElementString = getNumString(numElements);
numNullString = getNumString(numNulls);

formatSpec = " %s with %s %s and %s %s";
if numElements > 0
formatSpec = formatSpec + ":";
end
formatSpec = formatSpec + newline;
header = compose(formatSpec, className, numElements, elementString, numNulls, nullString);

header = compose(formatSpec, className, numElementString, elementString, numNullString, nullString);
header = char(header);
end
4 changes: 2 additions & 2 deletions matlab/src/matlab/+arrow/+array/Array.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ function validate(obj, opts)

methods (Access=protected)
function header = getHeader(obj)
name = matlab.mixin.CustomDisplay.getClassNameForHeader(obj);
fullClassName = matlab.mixin.CustomDisplay.getClassNameForHeader(obj);
numElements = obj.NumElements;
% TODO: Add NumValid and NumNull as properties to Array to
% avoid materializing the Valid property. This will improve
% performance for large arrays.
numNulls = nnz(~obj.Valid);
header = arrow.array.internal.display.getHeader(name, numElements, numNulls);
header = arrow.array.internal.display.getHeader(fullClassName, numElements, numNulls);
end

function displayScalarObject(obj)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
%GETCLASSNAMEFORDISPLAY Returns a display-ready class name string, optionally
%with a hyperlink when the MATLAB desktop is available.

% 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 OF CONDITIONS OF ANY KIND, either express or
% implied. See the License for the specific language governing
% permissions and limitations under the License.

function displayName = getClassNameForDisplay(fullClassName, opts)
arguments
fullClassName(1, 1) string
opts.BoldFont(1, 1) logical = true
end
% Extract the short class name (e.g., "BooleanArray" from "arrow.array.BooleanArray")
parts = split(fullClassName, ".");
shortName = parts(end);
displayName = arrow.internal.display.makeLinkString(...
HelpTarget=fullClassName, ...
Text=shortName, ...
BoldFont=opts.BoldFont);
end
25 changes: 25 additions & 0 deletions matlab/src/matlab/+arrow/+internal/+display/getNumString.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
%GETNUMSTRING Returns a string representation of a number, optionally bolded
%when the MATLAB desktop is available.

% 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 OF CONDITIONS OF ANY KIND, either express or
% implied. See the License for the specific language governing
% permissions and limitations under the License.

function str = getNumString(num)
if usejava("desktop")
str = compose("<strong>%d</strong>", num);
else
str = compose("%d", num);
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
%MAKEDIMENSIONSTRING Creates a string representation of array dimensions.

% 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 OF CONDITIONS OF ANY KIND, either express or
% implied. See the License for the specific language governing
% permissions and limitations under the License.

function dimensionString = makeDimensionString(arraySize)
dimensionString = string(arraySize);
dimensionString = join(dimensionString, char(215));
end
40 changes: 40 additions & 0 deletions matlab/src/matlab/+arrow/+internal/+display/makeLinkString.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
%MAKELINKSTRING Creates a hyperlink string if possible.

% 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.

function link = makeLinkString(opts)
arguments
opts.HelpTarget(1, 1) string {mustBeNonzeroLengthText}
opts.Text(1, 1) string {mustBeNonzeroLengthText}
% When displaying heterogeneous arrays, only the name of the
% closest shared ancestor class is displayed in bold. All other
% class names are not bolded.
opts.BoldFont(1, 1) logical = false
end

if usejava("desktop")
if opts.BoldFont
link = compose("<a href=""matlab:helpPopup('%s')""" + ...
" style=""font-weight:bold"">%s</a>", ...
opts.HelpTarget, opts.Text);
else
link = compose("<a href=""matlab:helpPopup('%s')"">%s</a>", ...
opts.HelpTarget, opts.Text);
end
else
link = opts.Text;
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@
opts.BoldFont(1, 1) logical
end

if opts.BoldFont
link = compose("<a href=""matlab:helpPopup('%s')""" + ...
" style=""font-weight:bold"">%s</a>", ...
opts.FullClassName, opts.ClassName);
else
link = compose("<a href=""matlab:helpPopup('%s')"">%s</a>", ...
opts.FullClassName, opts.ClassName);
end
link = arrow.internal.display.makeLinkString( ...
HelpTarget=opts.FullClassName, ...
Text=opts.ClassName, ...
BoldFont=opts.BoldFont);
end
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,11 @@
idx = strlength(names) == 0;
names(idx) = "<empty>";

names = arrayfun(@arrow.internal.display.boldFontIfPossible, names);
classNames = arrayfun(@(type) string(class(type)), types);
if usejava("desktop")
% When in desktop mode, the Command Window can interpret HTML tags
% to display bold font and hyperlinks.
names = compose("<strong>%s</strong>", names);
classNames = arrayfun(@(type) string(class(type)), types);

% Creates a string array with the following form:
%
% ["arrow.type.BooleanType" "Boolean" "arrow.type.StringType" "String" ...]
%
% This string array is passed to the compose call below. The
% format specifier operator supplied to compose contains two
% formatting operators (%s), so compose uses two elements from the
% string array (classNameAndIDs) at a time.
classNameAndIDs = strings([1 numel(typeIDs) * 2]);
classNameAndIDs(1:2:end-1) = classNames;
classNameAndIDs(2:2:end) = typeIDs;
typeIDs = compose("<a href=""matlab:helpPopup('%s')"" style=""font-weight:bold"">%s</a>", classNameAndIDs);
typeIDs = arrayfun(@(className, typeID) arrow.internal.display.makeLinkString( ...
HelpTarget=className, Text=typeID, BoldFont=true), classNames, typeIDs);
end

text = names + ": " + typeIDs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@
% implied. See the License for the specific language governing
% permissions and limitations under the License.

function header = getTabularHeader(className, numRows, numColumns)
import arrow.internal.display.boldFontIfPossible
function header = getTabularHeader(fullClassName, numRows, numColumns)
import arrow.internal.display.getClassNameForDisplay
import arrow.internal.display.getNumString
import arrow.internal.display.pluralizeStringIfNeeded

numRowsString = boldFontIfPossible(numRows);
numColsString = boldFontIfPossible(numColumns);
className = getClassNameForDisplay(fullClassName);
numRowsString = getNumString(numRows);
numColsString = getNumString(numColumns);
rowWordString = pluralizeStringIfNeeded(numRows, "row");
colWordString = pluralizeStringIfNeeded(numColumns, "column");
formatSpec = " Arrow %s with %s %s and %s %s";
if numColumns > 0
formatSpec = formatSpec + ":";
end
header = compose(formatSpec,className, numRowsString, rowWordString, numColsString, colWordString);
header = compose(formatSpec, className, numRowsString, rowWordString, numColsString, colWordString);
end
13 changes: 9 additions & 4 deletions matlab/src/matlab/+arrow/+tabular/Schema.m
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,19 @@
methods (Access=protected)

function header = getHeader(obj)
name = matlab.mixin.CustomDisplay.getClassNameForHeader(obj);
import arrow.internal.display.getClassNameForDisplay
import arrow.internal.display.getNumString

fullClassName = matlab.mixin.CustomDisplay.getClassNameForHeader(obj);
className = getClassNameForDisplay(fullClassName);
numFields = obj.NumFields;
numFieldsString = getNumString(numFields);
if numFields == 0
header = compose(" Arrow %s with 0 fields" + newline, name);
header = compose(" Arrow %s with %s fields" + newline, className, numFieldsString);
elseif numFields == 1
header = compose(" Arrow %s with %d field:" + newline, name, numFields);
header = compose(" Arrow %s with %s field:" + newline, className, numFieldsString);
else
header = compose(" Arrow %s with %d fields:" + newline, name, numFields);
header = compose(" Arrow %s with %s fields:" + newline, className, numFieldsString);
end
end

Expand Down
8 changes: 8 additions & 0 deletions matlab/src/matlab/+arrow/+type/Field.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@
end

methods (Access=protected)
function header = getHeader(obj)
import arrow.internal.display.getClassNameForDisplay

fullClassName = matlab.mixin.CustomDisplay.getClassNameForHeader(obj);
className = getClassNameForDisplay(fullClassName);
header = " " + className + " with properties:" + newline;
end

function groups = getPropertyGroups(~)
targets = ["Name", "Type"];
groups = matlab.mixin.util.PropertyGroup(targets);
Expand Down
37 changes: 36 additions & 1 deletion matlab/src/matlab/+arrow/+type/Type.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,42 @@

methods (Sealed, Access = protected)
function header = getHeader(obj)
header = getHeader@matlab.mixin.CustomDisplay(obj);
import arrow.internal.display.getClassNameForDisplay
import arrow.internal.display.makeLinkString
import arrow.internal.display.makeDimensionString

if isempty(obj)
fullClassName = "arrow.type.Type";
typeLink = getClassNameForDisplay(fullClassName);
dimensionString = makeDimensionString(size(obj));
header = " " + dimensionString + " " + typeLink + " array with properties:" + newline;
elseif isscalar(obj)
fullClassName = string(class(obj));
typeLink = getClassNameForDisplay(fullClassName);
header = " " + typeLink + " with properties:" + newline;
else
dimensionString = makeDimensionString(size(obj));
classNames = arrayfun(@(x) string(class(x)), obj);
uniqueClasses = unique(classNames);
if numel(uniqueClasses) == 1
typeLink = getClassNameForDisplay(uniqueClasses(1));
header = " " + dimensionString + " " + typeLink + " array with properties:" + newline;
else
heterogeneousLink = makeLinkString(HelpTarget="matlab.mixin.Heterogeneous", Text="heterogeneous", BoldFont=false);
baseClassName = string(class(obj));
baseClassLink = getClassNameForDisplay(baseClassName, BoldFont=true);
typeLinkParts = strings(size(uniqueClasses));
for ii = 1:numel(uniqueClasses)
c = uniqueClasses(ii);
parts = split(c, ".");
shortName = parts(end);
typeLinkParts(ii) = makeLinkString(HelpTarget=c, Text=shortName, BoldFont=false);
end
typeLinksStr = join(typeLinkParts, ", ");
header = " " + dimensionString + " " + heterogeneousLink + " " + baseClassLink + ...
" (" + typeLinksStr + ") array with properties:" + newline;
end
end
end

function groups = getPropertyGroups(obj)
Expand Down
6 changes: 3 additions & 3 deletions matlab/test/arrow/tabular/tSchema.m
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,8 @@ function TestIsEqualTrue(testCase)
]);

% Create a Schema with zero fields
schema3 = arrow.recordBatch(table).Schema;
schema4 = arrow.recordBatch(table).Schema;
schema3 = arrow.recordBatch(table()).Schema;
schema4 = arrow.recordBatch(table()).Schema;

testCase.verifyTrue(isequal(schema1, schema2));
testCase.verifyTrue(isequal(schema3, schema4));
Expand Down Expand Up @@ -514,7 +514,7 @@ function TestIsEqualFalse(testCase)
]);

% Create a Schema with zero fields
schema5 = arrow.recordBatch(table).Schema;
schema5 = arrow.recordBatch(table()).Schema;

% Have different number of fields
testCase.verifyFalse(isequal(schema1, schema2));
Expand Down
Loading