forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…he#37836) ### Rationale for this change We would like to change how `arrow.tabular.Schema`s are displayed in the Command Window. Below is the current display: ```matlab >> field1 = arrow.field("A", arrow.time32()); >> field2 = arrow.field("B", arrow.boolean()); >>s = arrow.schema([field1 field2]) s = A: time32[s] B: bool ``` This display is not very MATLAB-like. ### What changes are included in this PR? 1. Updated the display of `arrow.tabular.Schema`. Below is the new display: ```matlab >> field1 = arrow.field("A", arrow.time32()); >> field2 = arrow.field("B", arrow.boolean()); >> s = arrow.schema([field1 field2]) s = Arrow Schema with 2 fields: A: Time32 | B: Boolean ``` When MATLAB is opened in desktop mode, `Schema`, `Time32`, and `Boolean` are hyperlinks users can click on to view the help text for the different class types. ### Are these changes tested? Yes. Added three new test cases to `tSchema.m`: 1. `TestDisplaySchemaZeroFields` 2. `TestDisplaySchemaOneField` 3. `TestDisplaySchemaMultipleFields` ### Are there any user-facing changes? Yes. `arrow.tabular.Schema`s will be displayed differently in the Command Window. ### Notes Once apache#37826 is merged, I will rebase my changes and mark this PR as ready for review. * Closes: apache#37835 Authored-by: Sarah Gilmore <sgilmore@mathworks.com> Signed-off-by: Kevin Gurney <kgurney@mathworks.com>
- Loading branch information
1 parent
1bd3cba
commit 00efb06
Showing
5 changed files
with
131 additions
and
19 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
50 changes: 50 additions & 0 deletions
50
matlab/src/matlab/+arrow/+tabular/+internal/displaySchema.m
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,50 @@ | ||
%DISPLAYSCHEMA Generates arrow.tabular.Schema display text. | ||
|
||
% 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 text = displaySchema(schema) | ||
fields = schema.Fields; | ||
names = [fields.Name]; | ||
types = [fields.Type]; | ||
typeIDs = string([types.ID]); | ||
|
||
% Use <empty> as the sentinel for field names with zero characters. | ||
idx = strlength(names) == 0; | ||
names(idx) = "<empty>"; | ||
|
||
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); | ||
end | ||
|
||
text = names + ": " + typeIDs; | ||
text = " " + strjoin(text, " | "); | ||
end |
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