-
Notifications
You must be signed in to change notification settings - Fork 326
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
Initial implementation of Data.read_many
#11490
Changes from all commits
2476921
f55f11f
3689441
31c7a56
6af7d3e
3790469
a590747
bb7e34a
402bc40
ad8a048
31c0a2a
392136a
bce7b29
400b6ce
79bcc74
9539514
ffdc567
b5b9b1a
c34fb7f
0ebd984
e7cd8db
1897352
16bbae0
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import project.Data.Text.Text | ||
import project.Data.Vector.Vector | ||
|
||
## A common interface that represents a list of files that can be read. | ||
|
||
Various types (e.g. Vector, Column) can convert to this type to be able to be | ||
used in `Data.read_many`. | ||
type Many_Files_List | ||
## PRIVATE | ||
radeusgd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Value original_value paths_to_load:Vector | ||
|
||
## PRIVATE | ||
to_text self -> Text = | ||
"Many_Files_List "+self.original_value.to_text | ||
|
||
## PRIVATE | ||
to_display_text self -> Text = | ||
"Many_Files_List "+self.original_value.to_display_text | ||
|
||
## PRIVATE | ||
Many_Files_List.from (that : Vector) = | ||
Many_Files_List.Value that that |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import project.Any.Any | ||
import project.Data.Text.Text | ||
import project.Data.Read.Many_Files_List.Many_Files_List | ||
import project.Data.Vector.Vector | ||
import project.Error.Error | ||
import project.Errors.Common.Type_Error | ||
import project.Errors.Illegal_Argument.Illegal_Argument | ||
import project.Function.Function | ||
import project.Metadata.Display | ||
import project.Metadata.Widget | ||
import project.Nothing.Nothing | ||
import project.Panic.Panic | ||
from project.Data.Boolean import Boolean, False, True | ||
from project.Metadata.Choice import Option | ||
from project.Metadata.Widget import Single_Choice | ||
|
||
polyglot java import org.enso.base.read.ReadManyReturnSPI | ||
|
||
private _get_known_return_classes -> Vector = | ||
Vector.from_polyglot_array (ReadManyReturnSPI.get_types False) | ||
|
||
## A common interface that represents ways to return a list of files that have | ||
been read. | ||
type Return_As | ||
## PRIVATE | ||
Instance underlying | ||
radeusgd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## PRIVATE | ||
to_text self -> Text = self.underlying.to_text | ||
|
||
## PRIVATE | ||
to_display_text self -> Text = self.underlying.to_display_text | ||
|
||
## PRIVATE | ||
make_return self (input : Many_Files_List) (objects : Vector Any) = | ||
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. Why isn't this method 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 is used from within |
||
self.underlying.make_return input objects | ||
|
||
## PRIVATE | ||
Resolve an unresolved constructor to the actual type. | ||
private resolve value = case value of | ||
radeusgd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_ : Function -> | ||
types = _get_known_return_classes | ||
try_next idx = | ||
if idx >= types.length then Error.throw (Illegal_Argument.Error "Expected Return_As, but got a function.") else | ||
resolved = (types.at idx).resolve value | ||
if resolved.is_nothing then @Tail_Call try_next (idx + 1) else resolved | ||
try_next 0 | ||
_ : Return_As -> value | ||
_ -> Panic.throw (Type_Error.Error Return_As value "Expected `return` to be a Return_As type, but got {got}.") | ||
|
||
## PRIVATE | ||
default_widget : Widget | ||
default_widget = | ||
options = _get_known_return_classes.map .get_dropdown_options | ||
Single_Choice display=Display.Always values=options | ||
|
||
## PRIVATE | ||
type Return_As_Base | ||
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. Why isn't this type in its own 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. Because its constructors are actually supposed to be visible, only the type is hidden. Perhaps it can be moved to a separate module. |
||
## Will return a Vector of objects that were loaded. | ||
The order of the returned Vector is the same as in the input. | ||
Vector | ||
|
||
## PRIVATE | ||
get_dropdown_options : Vector Option | ||
get_dropdown_options = [Option "Vector" "..Vector"] | ||
|
||
## PRIVATE | ||
resolve value = | ||
Panic.catch Type_Error (value:Return_As_Base) _->Nothing | ||
|
||
## PRIVATE | ||
make_return self (input : Many_Files_List) (objects : Vector Any) = | ||
_ = input | ||
objects | ||
|
||
## PRIVATE | ||
Return_As.from (that : Return_As_Base) = | ||
Return_As.Instance that |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
private | ||
radeusgd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
from Standard.Base import all | ||
import Standard.Base.Data.Read.Many_Files_List.Many_Files_List | ||
import Standard.Base.Errors.Illegal_Argument.Illegal_Argument | ||
|
||
import project.Column.Column | ||
import project.Errors.Invalid_Value_Type | ||
import project.Table.Table | ||
import project.Value_Type.Value_Type | ||
|
||
find_files_list_in_table (that : Table) -> Many_Files_List = | ||
found_column = if that.column_count == 1 then that.at 0 else | ||
path_columns = that.select_columns "path" case_sensitivity=..Insensitive on_problems=..Report_Error | ||
not_found = path_columns.is_error || (path_columns.column_count == 0) | ||
if not_found then Error.throw (Illegal_Argument.Error "To use a Table as file list, it must be a single column or contain a `path` column (case insensitive).") else | ||
if path_columns.column_count > 1 then Error.throw (Illegal_Argument.Error "Multiple 'paths' column candidates found: "+path_columns.column_names.to_display_text+".") else | ||
path_columns.at 0 | ||
ensure_column_type_valid_to_be_files_list found_column <| | ||
Many_Files_List.Value that found_column.to_vector | ||
|
||
ensure_column_type_valid_to_be_files_list (column : Column) ~action = | ||
is_expected_type = case column.value_type of | ||
# Columns containing File objects will be Mixed | ||
Value_Type.Mixed -> True | ||
# Columns containing paths as Text will be Char | ||
Value_Type.Char _ _ -> True | ||
_ -> False | ||
if is_expected_type then action else | ||
Error.throw (Invalid_Value_Type.Column "Text or Mixed" column.value_type column.name) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.enso.base.read; | ||
|
||
@org.openide.util.lookup.ServiceProvider(service = ReadManyReturnSPI.class) | ||
public class BaseReadManyReturnSPI extends ReadManyReturnSPI { | ||
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. Repeating the terminology misuse - the Make 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. All of our SPI implementations are named according to this convention. If the convention is wrong, we should rename them all at once, which should be done separately from this PR. |
||
@Override | ||
protected String getModuleName() { | ||
return "Standard.Base.Data.Read.Return_As"; | ||
} | ||
|
||
@Override | ||
protected String getTypeName() { | ||
return "Return_As_Base"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.enso.base.read; | ||
|
||
import java.util.ServiceLoader; | ||
import org.enso.base.polyglot.EnsoMeta; | ||
import org.graalvm.polyglot.Value; | ||
|
||
public abstract class ReadManyReturnSPI { | ||
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. Missing documentation. |
||
private static final ServiceLoader<ReadManyReturnSPI> loader = | ||
ServiceLoader.load(ReadManyReturnSPI.class, ReadManyReturnSPI.class.getClassLoader()); | ||
|
||
public static Value[] get_types(boolean refresh) { | ||
if (refresh) { | ||
loader.reload(); | ||
} | ||
return loader.stream().map(provider -> provider.get().getTypeObject()).toArray(Value[]::new); | ||
} | ||
|
||
public Value getTypeObject() { | ||
return EnsoMeta.getType(getModuleName(), getTypeName()); | ||
} | ||
|
||
protected abstract String getModuleName(); | ||
|
||
protected abstract String getTypeName(); | ||
} |
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.
I'm not sure that I understand what a user would do with this option. Should it be on the graphical interface API?
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.
OK. I get what this is now. Guess we will improve the comment as we add more options.
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.
Happy to accept suggestions on what the doc could be. Perhaps I should add examples?
I hope in GUI it will be easy because we'll have a dropdown