-
Notifications
You must be signed in to change notification settings - Fork 324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sort output of S3_File.list
and Enso_File.list
#11929
Changes from 8 commits
53e4da8
21f017d
ee11a77
1780552
d151d5d
4ebf3f3
413e901
a771429
85e9ac1
cbb9fa7
f584add
d1acf61
86f8879
3eab006
46621d0
7f05c32
ce1b578
f9f9c72
cb4f970
72b045a
4cb2a19
7dede39
2b68104
b5b5ff6
1a0880a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,7 +187,7 @@ type S3_File | |
S3_File.Value (S3_Path.Value bucket key) self.credentials | ||
files = pair.second . map key-> | ||
S3_File.Value (S3_Path.Value bucket key) self.credentials | ||
sub_folders + files | ||
sub_folders + files . sort on=.s3_path | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Won't this just sort There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also we could just sort on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it better to not use a comparator? I was thinking of adding a comparator for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like it sorted the files and sub-folders properly:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd still add parentheses, the precedence of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Hmm, I guess we could do that yeah. But still I'd rely on comparing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
||
## ALIAS load bytes, open bytes | ||
ICON data_input | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import project.Data.Filter_Condition.Filter_Condition | |
import project.Data.Index_Sub_Range.Index_Sub_Range | ||
import project.Data.List.List | ||
import project.Data.Numbers.Integer | ||
import project.Data.Ordering.Ordering | ||
import project.Data.Pair.Pair | ||
import project.Data.Range.Range | ||
import project.Data.Sort_Direction.Sort_Direction | ||
|
@@ -20,6 +21,7 @@ import project.Errors.Problem_Behavior.Problem_Behavior | |
import project.Errors.Wrapped_Error.Wrapped_Error | ||
import project.Function.Function | ||
import project.Internal.Array_Like_Helpers | ||
import project.Internal.Ordering_Helpers.Default_Comparator | ||
import project.Math | ||
import project.Meta | ||
import project.Nothing.Nothing | ||
|
@@ -1563,3 +1565,24 @@ type No_Wrap | |
|
||
## PRIVATE | ||
Wrapped_Error.from (that : Map_Error) = Wrapped_Error.Value that that.inner_error | ||
|
||
type Vector_Comparator | ||
compare x y = | ||
min_length = x.length.min y.length | ||
when_prefixes_equal = | ||
## At this point, if the vectors are the same length, then they are | ||
identical; otherwise, the shorter one is lesser. | ||
if x.length == y.length then Ordering.Equal else | ||
Ordering.compare x.length y.length | ||
go i = | ||
if i >= min_length then when_prefixes_equal else | ||
x_elem = x.at i | ||
y_elem = y.at i | ||
Ordering.compare x_elem y_elem . and_then <| | ||
@Tail_Call go (i + 1) | ||
k = go 0 | ||
k | ||
|
||
hash x = Default_Comparator.hash_builtin x | ||
|
||
Comparable.from (that : Vector) = Comparable.new that Vector_Comparator | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm pretty sure this just re-implements I think we did not register it into Of course we can decide that it is beneficial to include a default There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The downside to making the comparable is that if a user accidentally nests vectors, and sorts them, they won't know they made a mistake. But it will be easy to see that the data is nested. Without a comparator, they'll get an error. The upside is that they'll be able to sort vectors containing more things. @JaroslavTulach You asked if modern languages allow this; Haskell does:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've removed the |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -261,6 +261,12 @@ add_specs suite_builder = | |
r3.should_be_a Vector | ||
r3.map .name . should_contain object_name | ||
|
||
group_builder.specify "list should sort its output" <| | ||
r = root.list | ||
r.should_be_a Vector | ||
r . should_equal (r.sort on=.s3_path) | ||
r . should_equal (r.sort on=(x-> x.s3_path.to_text)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed to |
||
|
||
group_builder.specify "will fail if no credentials are provided and no Default credentials are available" pending=(if AWS_Credential.is_default_credential_available then "Default AWS credentials are defined in the environment and this test has no way of overriding them, so it is impossible to test this scenario in such environment.") <| | ||
root_without_credentials = S3_File.new "s3://"+bucket_name+"/" | ||
r = root_without_credentials.list | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,12 @@ add_specs suite_builder setup:Cloud_Tests_Setup = suite_builder.group "Enso Clou | |
Data.list test_root.get . map .name . should_contain "test_file.json" | ||
Data.list test_root.get.path . map .name . should_contain "test_file.json" | ||
|
||
group_builder.specify "list should sort its output" <| | ||
r = Enso_File.home.list | ||
r.should_be_a Vector | ||
r . should_equal (r.sort on=.path) | ||
r . should_equal (r.sort on=.enso_path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed. |
||
|
||
group_builder.specify "should allow to create and delete a directory" <| | ||
my_name = "my_test_dir-" + (Random.uuid.take 5) | ||
my_dir = (test_root.get / my_name).create_directory | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
;-)
It would be easier to change the IDE to not display
from
methods in the component browser than adding this## PRIVATE
at every conversion method occurrence.