mirror of
https://github.com/enso-org/enso.git
synced 2024-12-23 01:21:33 +03:00
Linting and Groups update (#8357)
- Fix issues from the linter. - Rename the constructors for `Blank_Selector`. - Update various GROUP tags.
This commit is contained in:
parent
8eed0f1dd6
commit
347b5a7cf5
@ -33,7 +33,8 @@ list_buckets credentials:(AWS_Credential | Nothing)=Nothing = handle_s3_errors <
|
||||
buckets = client.listBuckets.buckets
|
||||
buckets.map b->b.name
|
||||
|
||||
## Gets the list of the items inside a bucket.
|
||||
## GROUP Standard.Base.Input
|
||||
Gets the list of the items inside a bucket.
|
||||
|
||||
Arguments:
|
||||
- bucket: the name of the bucket.
|
||||
|
@ -30,22 +30,25 @@ type S3_File
|
||||
## PRIVATE
|
||||
Value bucket:Text prefix:Text credentials:(AWS_Credential | Nothing)
|
||||
|
||||
## Gets the URI of this file
|
||||
## GROUP Standard.Base.Metadata
|
||||
Gets the URI of this file
|
||||
uri : Text
|
||||
uri self = "s3://" + (if self.bucket=="" then "" else (self.bucket+"/"+self.prefix))
|
||||
|
||||
## Checks if the folder or file exists
|
||||
## GROUP Standard.Base.Metadata
|
||||
Checks if the folder or file exists
|
||||
exists : Boolean
|
||||
exists self = if self.bucket == "" then True else
|
||||
if self.prefix == "" then S3.head self.bucket "" self.credentials . is_error . not else
|
||||
pair = S3.read_bucket self.bucket self.prefix self.credentials max_count=1
|
||||
pair.second.length > 0
|
||||
|
||||
## Checks if this is a folder
|
||||
## GROUP Standard.Base.Metadata
|
||||
Checks if this is a folder
|
||||
is_directory : Boolean
|
||||
is_directory self = self.prefix=="" || self.prefix.ends_with "/"
|
||||
|
||||
## GROUP Metadata
|
||||
## GROUP Standard.Base.Metadata
|
||||
Gets the size of a file in bytes.
|
||||
size : Integer
|
||||
size self =
|
||||
@ -92,7 +95,7 @@ type S3_File
|
||||
response_body.with_stream action
|
||||
|
||||
## ALIAS load, open
|
||||
GROUP Input
|
||||
GROUP Standard.Base.Input
|
||||
Read a file using the specified file format
|
||||
|
||||
Arguments:
|
||||
@ -136,7 +139,7 @@ type S3_File
|
||||
read_text self (encoding=Encoding.utf_8) (on_problems=Problem_Behavior.Report_Warning) =
|
||||
self.read (Plain_Text encoding) on_problems
|
||||
|
||||
## GROUP Operators
|
||||
## GROUP Standard.Base.Operators
|
||||
Join two path segments together.
|
||||
|
||||
Arguments:
|
||||
@ -159,7 +162,7 @@ type S3_File
|
||||
path = loop initial parts
|
||||
S3_File.Value self.bucket path self.credentials
|
||||
|
||||
## GROUP Calculations
|
||||
## GROUP Standard.Base.Calculations
|
||||
Join two or more path segments together, normalizing the `..` and `.` subpaths.
|
||||
|
||||
Arguments:
|
||||
@ -169,7 +172,7 @@ type S3_File
|
||||
_ : Vector -> (subpaths.fold self c->p-> c / p)
|
||||
_ -> self.join [subpaths]
|
||||
|
||||
## GROUP Metadata
|
||||
## GROUP Standard.Base.Metadata
|
||||
Returns the name of this file.
|
||||
name : Text
|
||||
name self = if self.prefix == "" then self.bucket else
|
||||
@ -177,7 +180,7 @@ type S3_File
|
||||
last_index = trimmed.lastIndexOf "/"
|
||||
if last_index == Nothing then trimmed else trimmed.drop (First last_index+1)
|
||||
|
||||
## GROUP Metadata
|
||||
## GROUP Standard.Base.Metadata
|
||||
Returns the extension of the file.
|
||||
extension : Text
|
||||
extension self = if self.is_directory then Error.throw (S3_Error.Error "Directories do not have extensions." self.uri) else
|
||||
@ -187,7 +190,7 @@ type S3_File
|
||||
extension = name.drop (Index_Sub_Range.First last_dot.start)
|
||||
if extension == "." then "" else extension
|
||||
|
||||
## GROUP Input
|
||||
## GROUP Standard.Base.Input
|
||||
Lists files contained in the directory denoted by this file.
|
||||
|
||||
Arguments:
|
||||
|
@ -21,7 +21,7 @@ import project.System.Input_Stream.Input_Stream
|
||||
import project.System.Output_Stream.Output_Stream
|
||||
from project.Data.Boolean import Boolean, False, True
|
||||
from project.Data.Text.Extensions import all
|
||||
from project.System.File_Format import Auto_Detect, File_Format, Bytes, Plain_Text_Format
|
||||
from project.System.File_Format import Auto_Detect, Bytes, File_Format, Plain_Text_Format
|
||||
|
||||
type Enso_File
|
||||
## PRIVATE
|
||||
@ -45,14 +45,16 @@ type Enso_File
|
||||
Enso_Asset_Type.Data_Link -> Utils.secrets_api + "/" + self.id
|
||||
Enso_Asset_Type.Secret -> Error.throw (Illegal_Argument.Error "Secrets cannot be accessed directly.")
|
||||
|
||||
## Checks if the folder or file exists
|
||||
## GROUP Metadata
|
||||
Checks if the folder or file exists
|
||||
exists : Boolean
|
||||
exists self =
|
||||
auth_header = Utils.authorization_header
|
||||
response = HTTP.fetch self.internal_uri HTTP_Method.Get [auth_header]
|
||||
response.code.is_success
|
||||
|
||||
## Checks if this is a folder
|
||||
## GROUP Metadata
|
||||
Checks if this is a folder
|
||||
is_directory : Boolean
|
||||
is_directory self = self.asset_type == Enso_Asset_Type.Directory
|
||||
|
||||
@ -163,7 +165,8 @@ type Enso_File
|
||||
extension = name.drop (Index_Sub_Range.First last_dot.start)
|
||||
if extension == "." then "" else extension
|
||||
|
||||
## Gets a list of assets within self.
|
||||
## GROUP Input
|
||||
Gets a list of assets within self.
|
||||
list : Vector Enso_File
|
||||
list self = if self.asset_type != Enso_Asset_Type.Directory then Error.throw (Illegal_Argument.Error "Only directories can be listed.") else
|
||||
auth_header = Utils.authorization_header
|
||||
|
@ -27,7 +27,7 @@ type Enso_Secret
|
||||
- parent: The parent folder for the secret. If `Nothing` then it will be
|
||||
created in the root folder.
|
||||
create : Text -> Text -> Enso_File | Nothing -> Enso_Secret
|
||||
create name:Text value:Text parent:(Enso_File|Nothing)=Nothing = if name == "" then Error.throw (Illegal_Argument.Error "Secret name cannot be empty") else
|
||||
create name:Text value:Text parent:(Enso_File | Nothing)=Nothing = if name == "" then Error.throw (Illegal_Argument.Error "Secret name cannot be empty") else
|
||||
if Context.Output.is_enabled.not then Error.throw (Forbidden_Operation.Error "Creating a secret is forbidden as the Output context is disabled.") else
|
||||
if name.starts_with "connection-" then Error.throw (Illegal_Argument.Error "Secret name cannot start with 'connection-'") else
|
||||
if Enso_Secret.exists name parent then Error.throw (Illegal_Argument.Error "Secret with this name already exists") else
|
||||
@ -38,7 +38,8 @@ type Enso_Secret
|
||||
response.if_not_error <|
|
||||
Enso_Secret.get name parent
|
||||
|
||||
## Deletes a secret.
|
||||
## GROUP Output
|
||||
Deletes a secret.
|
||||
delete : Enso_Secret
|
||||
delete self =
|
||||
if Context.Output.is_enabled.not then Error.throw (Forbidden_Operation.Error "Deleting a secret is forbidden as the Output context is disabled.") else
|
||||
@ -47,13 +48,14 @@ type Enso_Secret
|
||||
response = HTTP.post uri Request_Body.Empty HTTP_Method.Delete [auth_header]
|
||||
response.if_not_error self
|
||||
|
||||
## Gets a list of all the secrets in the folder.
|
||||
## GROUP Input
|
||||
Gets a list of all the secrets in the folder.
|
||||
|
||||
Arguments:
|
||||
- folder: The folder to get the secrets from. If `Nothing` then will get
|
||||
the secrets from the root folder.
|
||||
list : Enso_File | Nothing -> Vector Enso_Secret
|
||||
list parent:(Enso_File|Nothing)=Nothing =
|
||||
list parent:(Enso_File | Nothing)=Nothing =
|
||||
auth_header = Utils.authorization_header
|
||||
auth_header.if_not_error <|
|
||||
headers = if parent.is_nothing then [auth_header] else [auth_header, ["parent_id", Enso_File.id]]
|
||||
@ -71,17 +73,18 @@ type Enso_Secret
|
||||
- parent: The parent folder for the secret. If `Nothing` then will check
|
||||
in the root folder.
|
||||
get : Text -> Enso_File | Nothing -> Enso_Secret ! Not_Found
|
||||
get name:Text parent:(Enso_File|Nothing)=Nothing =
|
||||
get name:Text parent:(Enso_File | Nothing)=Nothing =
|
||||
Enso_Secret.list parent . find s-> s.name == name
|
||||
|
||||
## Checks if a Secret exists.
|
||||
## GROUP Metadata
|
||||
Checks if a Secret exists.
|
||||
|
||||
Arguments:
|
||||
- name: The name of the secret
|
||||
- parent: The parent folder for the secret. If `Nothing` then will check
|
||||
in the root folder.
|
||||
exists : Text -> Enso_File | Nothing -> Boolean
|
||||
exists name:Text parent:(Enso_File|Nothing)=Nothing =
|
||||
exists name:Text parent:(Enso_File | Nothing)=Nothing =
|
||||
Enso_Secret.list parent . any s-> s.name == name
|
||||
|
||||
## PRIVATE
|
||||
|
@ -275,8 +275,8 @@ sql_like_to_regex sql_pattern =
|
||||
Regex.compile regex_pattern
|
||||
|
||||
## PRIVATE
|
||||
unify_condition_or_predicate : Filter_Condition|(Any->Boolean) -> (Any -> Boolean)
|
||||
unify_condition_or_predicate (condition_or_predicate : Filter_Condition | Function) =
|
||||
unify_condition_or_predicate : Filter_Condition | (Any -> Boolean) -> (Any -> Boolean)
|
||||
unify_condition_or_predicate (condition_or_predicate : Filter_Condition | (Any -> Boolean)) =
|
||||
case condition_or_predicate of
|
||||
condition : Filter_Condition -> condition.to_predicate
|
||||
predicate -> handle_constructor_missing_arguments predicate predicate
|
||||
|
@ -19,7 +19,7 @@ from project.Data.Boolean import Boolean, False, True
|
||||
from project.Data.Range.Extensions import all
|
||||
from project.Metadata.Choice import Option
|
||||
from project.Metadata.Widget import Single_Choice
|
||||
from project.Random import Random, get_default_seed
|
||||
from project.Random import get_default_seed, Random
|
||||
|
||||
type Index_Sub_Range
|
||||
## Select the first `count` items.
|
||||
|
@ -210,7 +210,8 @@ type JS_Object
|
||||
to_default_visualization_data self =
|
||||
render self
|
||||
|
||||
## Creates an Enso object from the JS_Object.
|
||||
## GROUP Conversions
|
||||
Creates an Enso object from the JS_Object.
|
||||
into : Any -> Any
|
||||
into self target_type = case target_type of
|
||||
JS_Object -> self
|
||||
|
@ -199,8 +199,8 @@ type Date_Time_Formatter
|
||||
pattern. If not specified, defaults to `Locale.default`. If passing a
|
||||
`DateTimeFormatter` instance and this argument is set, it will
|
||||
overwrite the original locale of that formatter.
|
||||
from_java : Text|DateTimeFormatter -> Locale -> Date_Time_Formatter ! Illegal_Argument
|
||||
from_java pattern (locale:Locale|Nothing=Nothing) = case pattern of
|
||||
from_java : Text | DateTimeFormatter -> Locale | Nothing -> Date_Time_Formatter ! Illegal_Argument
|
||||
from_java pattern locale:(Locale | Nothing)=Nothing = case pattern of
|
||||
java_formatter : DateTimeFormatter ->
|
||||
amended_formatter = case locale of
|
||||
Nothing -> java_formatter
|
||||
|
@ -159,7 +159,8 @@ type Time_Zone
|
||||
zone_id : Text
|
||||
zone_id self = @Builtin_Method "Time_Zone.zone_id"
|
||||
|
||||
## Get the offset in seconds at given date time.
|
||||
## GROUP DateTime
|
||||
Get the offset in seconds at given date time.
|
||||
Arguments:
|
||||
- at: The date to compute offset at.
|
||||
|
||||
|
@ -89,8 +89,8 @@ type Vector a
|
||||
> Example
|
||||
Turn a list into a vector.
|
||||
Vector.collect (List.Cons 1 <| List.Cons 2 <| List.Nil) .x .xs stop_at=(_==List.Nil)
|
||||
collect : Any -> (Any -> Any) -> (Any -> Any) -> Integer | Nothing -> ((Any -> Boolean) | Nothing) -> Vector Any
|
||||
collect seq element:(Any -> Any) next:(Any->Any) limit:(Integer|Nothing)=Nothing stop_at:(Any->Boolean)=(_==Nothing) =
|
||||
collect : Any -> (Any -> Any) -> (Any -> Any) -> Integer | Nothing -> (Any -> Boolean) -> Vector Any
|
||||
collect seq element:(Any -> Any) next:(Any -> Any) limit:(Integer | Nothing)=Nothing stop_at:(Any -> Boolean)=(_==Nothing) =
|
||||
b = Vector.new_builder (if limit.is_nothing then 10 else limit)
|
||||
iterate item remaining = if remaining == 0 || (stop_at item) then b.to_vector else
|
||||
b.append <| element item
|
||||
@ -722,8 +722,8 @@ type Vector a
|
||||
Concatenate two single-element vectors.
|
||||
|
||||
[1] + [2]
|
||||
+ : Vector Any -> Vector Any
|
||||
+ self that:(Array|Vector) = case that of
|
||||
+ : Vector Any | Array -> Vector Any
|
||||
+ self that:(Vector | Array) = case that of
|
||||
_ : Vector -> Vector.insert_builtin self self.length that
|
||||
_ : Array -> self + Vector.from_polyglot_array that
|
||||
|
||||
|
@ -36,7 +36,8 @@ polyglot java import org.xml.sax.SAXException
|
||||
polyglot java import org.xml.sax.SAXParseException
|
||||
|
||||
type XML_Document
|
||||
## Read an XML document from a file.
|
||||
## GROUP Input
|
||||
Read an XML document from a file.
|
||||
|
||||
Arguments:
|
||||
- file: the `File` to read the XML document from.
|
||||
@ -71,7 +72,8 @@ type XML_Document
|
||||
XML_Error.handle_java_exceptions <|
|
||||
input_stream.with_java_stream java_stream-> XML_Document.from_source java_stream
|
||||
|
||||
## Read an XML document from a string.
|
||||
## GROUP Conversions
|
||||
Read an XML document from a string.
|
||||
|
||||
Arguments:
|
||||
- xml_string: The string to read the XML document from.
|
||||
@ -98,7 +100,8 @@ type XML_Document
|
||||
XML_Utils.setCustomErrorHandler document_builder
|
||||
XML_Document.Value (document_builder.parse input_source)
|
||||
|
||||
## Get the root element of the document.
|
||||
## GROUP Metadata
|
||||
Get the root element of the document.
|
||||
|
||||
> Example
|
||||
Get the root element of a document.
|
||||
@ -125,7 +128,8 @@ type XML_Document
|
||||
Value (java_document:Document)
|
||||
|
||||
type XML_Element
|
||||
## Gets the tag of an XML element.
|
||||
## GROUP Metadata
|
||||
Gets the tag of an XML element.
|
||||
|
||||
> Example
|
||||
Get the tag of an XML element.
|
||||
@ -137,7 +141,8 @@ type XML_Element
|
||||
XML_Error.handle_java_exceptions <|
|
||||
self.java_element.getNodeName
|
||||
|
||||
## Gets a child of an XML element.
|
||||
## GROUP Selections
|
||||
Gets a child of an XML element.
|
||||
|
||||
Arguments:
|
||||
- key: If an `Integer`, returns the element at position `at` in its list
|
||||
@ -156,12 +161,13 @@ type XML_Element
|
||||
root.get "@bar"
|
||||
# => "one"
|
||||
get : Text | Integer -> Any -> Any | Text | XML_Element | Vector (Text | XML_Element) ! No_Such_Key | Index_Out_Of_Bounds | XML_Error
|
||||
get self key:(Text|Integer) ~if_missing=Nothing =
|
||||
get self key:(Text | Integer) ~if_missing=Nothing =
|
||||
case key of
|
||||
_ : Integer -> self.children_cache.get key if_missing
|
||||
_ : Text -> if is_attribute_key key then self.get_xpath key . get 0 if_missing else self.get_xpath key
|
||||
|
||||
## Gets a child or attribute of an XML element.
|
||||
## GROUP Selections
|
||||
Gets a child or attribute of an XML element.
|
||||
|
||||
Arguments:
|
||||
- key: If an `Integer`, returns the element at position `at` in its list
|
||||
@ -182,7 +188,7 @@ type XML_Element
|
||||
root.at "@bar"
|
||||
# => "one"
|
||||
at : Text | Integer -> Text | XML_Element | Vector (Text | XML_Element) ! No_Such_Key | Index_Out_Of_Bounds | XML_Error
|
||||
at self key:(Text|Integer) =
|
||||
at self key:(Text | Integer) =
|
||||
if_missing = case key of
|
||||
_ : Integer -> Error.throw (Index_Out_Of_Bounds.Error key self.child_count)
|
||||
_ : Text -> Error.throw (No_Such_Key.Error self key)
|
||||
@ -205,7 +211,8 @@ type XML_Element
|
||||
xpath = XPathFactory.newInstance.newXPath
|
||||
only_wanted_nodes (xpath.evaluate key self.java_element XPathConstants.NODESET)
|
||||
|
||||
## Gets the child elements of an XML element.
|
||||
## GROUP Selections
|
||||
Gets the child elements of an XML element.
|
||||
|
||||
`children` only returns child elements and child text nodes that are not
|
||||
100% whitespace. Other node types, such as comments, are not included.
|
||||
@ -216,7 +223,8 @@ type XML_Element
|
||||
children : Vector (XML_Element | Text) ! XML_Error
|
||||
children self = self.children_cache
|
||||
|
||||
## Gets the number children of an XML element.
|
||||
## GROUP Metadata
|
||||
Gets the number children of an XML element.
|
||||
|
||||
`child_count` only counts child elements and child text nodes that are
|
||||
not 100% whitespace. Other node types, such as comments, are not included
|
||||
@ -230,7 +238,8 @@ type XML_Element
|
||||
child_count : Integer ! XML_Error
|
||||
child_count self = self.children_cache.length
|
||||
|
||||
## Get an attribute of an XML element.
|
||||
## GROUP Selections
|
||||
Get an attribute of an XML element.
|
||||
|
||||
Arguments:
|
||||
- name: The name of the attribute to get.
|
||||
@ -248,7 +257,8 @@ type XML_Element
|
||||
attr = self.java_element.getAttributeNode name
|
||||
if attr.is_nothing then if_missing else attr.getValue
|
||||
|
||||
## Gets a map containing f the attributes of an XML element.
|
||||
## GROUP Selections
|
||||
Gets a map containing of the attributes of an XML element.
|
||||
|
||||
> Example
|
||||
XML_Document.from_text '<foo bar="one">hello</foo>' . root_element . attributes
|
||||
@ -262,7 +272,8 @@ type XML_Element
|
||||
[node.getNodeName, node.getNodeValue]
|
||||
Map.from_vector keys_and_values
|
||||
|
||||
## Gets the text (non-markup) contents of the element and its descendants,
|
||||
## GROUP Selections
|
||||
Gets the text (non-markup) contents of the element and its descendants,
|
||||
if any.
|
||||
|
||||
> Example
|
||||
@ -300,7 +311,8 @@ type XML_Element
|
||||
XML_Error.handle_java_exceptions <|
|
||||
XML_Utils.innerXML self.java_element
|
||||
|
||||
## Gets elements matching a given tag name.
|
||||
## GROUP Metadata
|
||||
Gets elements matching a given tag name.
|
||||
|
||||
This searches through all descendants of the node, not just immediate children.
|
||||
|
||||
|
@ -634,7 +634,7 @@ type Instrumentor
|
||||
- fn: The callback function accepting UUID and computed value
|
||||
- expression: Expression to evaluate on_return - by default Nothing -
|
||||
e.g. to provide the return value of the function
|
||||
on_return self (fn : Text -> Any -> Nothing) (expression : Text|Nothing)=Nothing =
|
||||
on_return self (fn : Text -> Any -> Nothing) expression:(Text | Nothing)=Nothing =
|
||||
new = instrumentor_builtin "onReturn" [ self.impl, fn, expression ]
|
||||
Instrumentor.Value new
|
||||
|
||||
|
@ -34,7 +34,7 @@ type Header
|
||||
|
||||
example_new = Header.new "My_Header" "my header's value"
|
||||
new : Text -> Text | Enso_Secret -> Header
|
||||
new name:Text value:(Text|Enso_Secret) = Header.Value name value
|
||||
new name:Text value:(Text | Enso_Secret) = Header.Value name value
|
||||
|
||||
## Create an "Accept" header.
|
||||
|
||||
@ -115,7 +115,7 @@ type Header
|
||||
|
||||
example_content_type = Header.content_type "my_type"
|
||||
content_type : Text -> Encoding | Nothing -> Header
|
||||
content_type value:Text encoding:(Encoding|Nothing)=Nothing =
|
||||
content_type value:Text encoding:(Encoding | Nothing)=Nothing =
|
||||
charset = if encoding.is_nothing then "" else "; charset="+encoding.character_set
|
||||
Header.Value Header.content_type_header_name value+charset
|
||||
|
||||
|
@ -64,7 +64,8 @@ type Response
|
||||
content_type_optional = self.internal_http_response.headers.firstValue "Content-Type"
|
||||
if content_type_optional.isPresent then content_type_optional.get else Nothing
|
||||
|
||||
## Get the response content length in bytes.
|
||||
## GROUP Metadata
|
||||
Get the response content length in bytes.
|
||||
This method uses the `Content-Length` header, and does not read the body.
|
||||
If the header is not present will return Nothing.
|
||||
content_length : Integer | Nothing
|
||||
|
@ -108,7 +108,7 @@ type Response_Body
|
||||
_ -> self
|
||||
|
||||
## ALIAS parse
|
||||
GROUP Conversions
|
||||
GROUP Input
|
||||
Uses the format to decode the body.
|
||||
If using `Auto_Detect`, the content-type will be used to determine the
|
||||
format.
|
||||
|
@ -141,13 +141,14 @@ type URI
|
||||
query : Text | Nothing
|
||||
query self = self.internal_uri.getQuery
|
||||
|
||||
## Adds a query parameter to the URI
|
||||
## GROUP Calculations
|
||||
Adds a query parameter to the URI
|
||||
|
||||
Arguments:
|
||||
- key: The key of the query parameter.
|
||||
- value: The value of the query parameter.
|
||||
add_query_argument : Text -> Text | Enso_Secret -> URI
|
||||
add_query_argument self key:Text value:(Text|Enso_Secret) =
|
||||
add_query_argument self key:Text value:(Text | Enso_Secret) =
|
||||
URI_With_Query.Value self [Pair.new key value]
|
||||
|
||||
## Get the fragment part of this URI.
|
||||
|
@ -43,13 +43,14 @@ type URI_With_Query
|
||||
(EnsoSecretHelper.encodeArg p.first True) + "=" + (EnsoSecretHelper.encodeArg p.second False)
|
||||
(if base_query == "" then "" else base_query + "&") + (query_params.join "&")
|
||||
|
||||
## Adds a query parameter to the URI
|
||||
## GROUP Calculations
|
||||
Adds a query parameter to the URI
|
||||
|
||||
Arguments:
|
||||
- key: The key of the query parameter.
|
||||
- value: The value of the query parameter.
|
||||
add_query_argument : Text -> Text | Enso_Secret -> URI
|
||||
add_query_argument self key:Text value:(Text|Enso_Secret) =
|
||||
add_query_argument self key:Text value:(Text | Enso_Secret) =
|
||||
URI_With_Query.Value self.uri self.parameters+[Pair.new key value]
|
||||
|
||||
## PRIVATE
|
||||
@ -94,11 +95,13 @@ type URI_With_Query
|
||||
host : Text | Nothing
|
||||
host self = self.uri.host
|
||||
|
||||
## Get the authority (user info and host) part of this URI.
|
||||
## GROUP Metadata
|
||||
Get the authority (user info and host) part of this URI.
|
||||
authority : Text | Nothing
|
||||
authority self = self.uri.authority
|
||||
|
||||
## Get the port part of this URI.
|
||||
## GROUP Metadata
|
||||
Get the port part of this URI.
|
||||
port : Text | Nothing
|
||||
port self = self.uri.port
|
||||
|
||||
@ -107,6 +110,7 @@ type URI_With_Query
|
||||
path : Text | Nothing
|
||||
path self = self.uri.path
|
||||
|
||||
## Get the fragment part of this URI.
|
||||
## GROUP Metadata
|
||||
Get the fragment part of this URI.
|
||||
fragment : Text | Nothing
|
||||
fragment self = self.uri.fragment
|
||||
|
@ -25,6 +25,7 @@ polyglot java import java.util.UUID
|
||||
polyglot java import org.enso.base.random.Random_Utils
|
||||
polyglot java import org.enso.base.random.RandomInstanceHolder
|
||||
|
||||
## Type for creating random values.
|
||||
type Random
|
||||
## PRIVATE
|
||||
GROUP Random
|
||||
@ -41,8 +42,8 @@ type Random
|
||||
|
||||
rng = Random.oew_generator 42
|
||||
i = rng.integer 0 10
|
||||
new_generator : Integer -> Random_Generator
|
||||
new_generator (seed:Integer|Nothing=Nothing) = Random_Generator.new seed
|
||||
new_generator : Integer | Nothing -> Random_Generator
|
||||
new_generator seed:(Integer | Nothing)=Nothing = Random_Generator.new seed
|
||||
|
||||
## GROUP Random
|
||||
TEXT_ONLY
|
||||
|
@ -100,7 +100,7 @@ type Column
|
||||
- warn_if_more_rows: if set to `True`, a warning is attached to the
|
||||
result if the number of rows returned by the query exceeds `max_rows`.
|
||||
read : (Nothing | Integer) -> Boolean -> Materialized_Column
|
||||
read self (max_rows : Integer | Nothing = 1000) (warn_if_more_rows:Boolean = True) =
|
||||
read self (max_rows : Nothing | Integer = 1000) (warn_if_more_rows:Boolean = True) =
|
||||
self.to_table.read max_rows warn_if_more_rows . at 0
|
||||
|
||||
## GROUP Standard.Base.Conversions
|
||||
@ -1108,7 +1108,7 @@ type Column
|
||||
sort self order=Sort_Direction.Ascending =
|
||||
self.to_table.order_by [Sort_Column.Index 0 order] . at 0
|
||||
|
||||
## ALIAS first, last, slice, sample
|
||||
## ALIAS first, last, sample, slice
|
||||
GROUP Standard.Base.Selections
|
||||
Creates a new Column with the specified range of rows from the input
|
||||
Column.
|
||||
@ -1417,7 +1417,7 @@ type Column
|
||||
unusual events like DST.
|
||||
@period Date_Time_Helpers.make_period_selector_for_column
|
||||
date_add : (Column | Integer) -> Date_Period | Time_Period -> Column ! Invalid_Value_Type | Illegal_Argument
|
||||
date_add self amount (period : Date_Period|Time_Period = default_date_period self) =
|
||||
date_add self amount (period : Date_Period | Time_Period = default_date_period self) =
|
||||
Value_Type.expect_type self .is_date_or_time "date/time" <|
|
||||
my_type = self.inferred_precise_value_type
|
||||
Value_Type.expect_integer amount <|
|
||||
@ -1602,7 +1602,8 @@ type Column
|
||||
check_cast_compatibility self.value_type value_type <|
|
||||
self.internal_do_cast value_type on_problems
|
||||
|
||||
## Change the value type of the column to a more specific one, based on its
|
||||
## GROUP Standard.Base.Conversions
|
||||
Change the value type of the column to a more specific one, based on its
|
||||
contents.
|
||||
|
||||
This operation is currently not available in the Database backend.
|
||||
@ -1657,7 +1658,7 @@ type Column
|
||||
_ = [function, skip_nothing, expected_value_type]
|
||||
Error.throw <| Unsupported_Database_Operation.Error "`Column.map` is not supported in the Database backends."
|
||||
|
||||
## ALIAS combine, merge, join by row position
|
||||
## ALIAS combine, join by row position, merge
|
||||
|
||||
Applies `function` to consecutive pairs of elements of `self` and `that`
|
||||
and returns a column of results.
|
||||
|
@ -64,7 +64,7 @@ import project.Internal.IR.SQL_Expression.SQL_Expression
|
||||
import project.Internal.IR.SQL_Join_Kind.SQL_Join_Kind
|
||||
import project.Internal.SQL_Type_Reference.SQL_Type_Reference
|
||||
from project.Data.Take_Drop_Helpers import Take_Drop
|
||||
from project.Errors import Integrity_Error, Table_Not_Found, Unsupported_Database_Operation, SQL_Error
|
||||
from project.Errors import Integrity_Error, SQL_Error, Table_Not_Found, Unsupported_Database_Operation
|
||||
|
||||
polyglot java import java.sql.JDBCType
|
||||
polyglot java import java.util.UUID
|
||||
@ -275,7 +275,7 @@ type Table
|
||||
|
||||
Arguments:
|
||||
- when: By default, only columns consisting of all blank cells are
|
||||
selected. If set to Blank_Selector.Any_Cell_Blank, columns with one or
|
||||
selected. If set to Blank_Selector.Any_Cell, columns with one or
|
||||
more blank values are selected.
|
||||
- treat_nans_as_blank: specified whether `Number.nan` is considered as
|
||||
blank. By default, it is not.
|
||||
@ -288,7 +288,7 @@ type Table
|
||||
|
||||
table.select_blank_columns
|
||||
select_blank_columns : Blank_Selector -> Boolean -> Table
|
||||
select_blank_columns self (when:Blank_Selector = Blank_Selector.All_Cells_Blank) treat_nans_as_blank=False =
|
||||
select_blank_columns self (when:Blank_Selector = Blank_Selector.All_Cells) treat_nans_as_blank=False =
|
||||
new_columns = self.columns_helper.select_blank_columns_helper when treat_nans_as_blank
|
||||
if new_columns.length == 0 then Error.throw (No_Output_Columns) else
|
||||
self.updated_columns new_columns
|
||||
@ -301,7 +301,7 @@ type Table
|
||||
|
||||
Arguments:
|
||||
- when: By default, only columns consisting of all blank cells are
|
||||
selected. If set to Blank_Selector.Any_Cell_Blank, columns with one or
|
||||
selected. If set to Blank_Selector.Any_Cell, columns with one or
|
||||
more blank values are selected.
|
||||
- treat_nans_as_blank: specified whether `Number.nan` is considered as
|
||||
blank. By default, it is not.
|
||||
@ -314,7 +314,7 @@ type Table
|
||||
|
||||
table.remove_blank_columns
|
||||
remove_blank_columns : Blank_Selector -> Boolean -> Table
|
||||
remove_blank_columns self (when:Blank_Selector = Blank_Selector.All_Cells_Blank) treat_nans_as_blank=False =
|
||||
remove_blank_columns self (when:Blank_Selector = Blank_Selector.All_Cells) treat_nans_as_blank=False =
|
||||
new_columns = self.columns_helper.select_blank_columns_helper when treat_nans_as_blank invert_selection=True
|
||||
if new_columns.length == 0 then Error.throw (No_Output_Columns) else
|
||||
self.updated_columns new_columns
|
||||
@ -558,8 +558,8 @@ type Table
|
||||
people.filter "age" (age -> (age%10 == 0))
|
||||
@column Widget_Helpers.make_column_name_selector
|
||||
@filter Widget_Helpers.make_filter_condition_selector
|
||||
filter : (Column | Text | Integer) -> (Filter_Condition|(Any->Boolean)) -> Problem_Behavior -> Table ! No_Such_Column | Index_Out_Of_Bounds | Invalid_Value_Type
|
||||
filter self column (filter : Filter_Condition | Function = Filter_Condition.Equal True) on_problems=Report_Warning = case column of
|
||||
filter : (Column | Text | Integer) -> (Filter_Condition | (Any -> Boolean)) -> Problem_Behavior -> Table ! No_Such_Column | Index_Out_Of_Bounds | Invalid_Value_Type
|
||||
filter self column (filter : Filter_Condition | (Any -> Boolean) = Filter_Condition.Equal True) on_problems=Report_Warning = case column of
|
||||
_ : Column ->
|
||||
mask filter_column = case Helpers.check_integrity self filter_column of
|
||||
False ->
|
||||
@ -1335,7 +1335,8 @@ type Table
|
||||
on_problems.attach_problems_before limit_problems <|
|
||||
self.join_or_cross_join right join_kind=Join_Kind_Cross.Cross on=[] right_prefix on_problems
|
||||
|
||||
## Replaces values in this table by values from a lookup table.
|
||||
## GROUP Standard.Base.Calculations
|
||||
Replaces values in this table by values from a lookup table.
|
||||
New values are looked up in the lookup table based on the `key_columns`.
|
||||
Columns found in the lookup table values are replaced by values from the
|
||||
lookup. Columns not found are left unchanged.
|
||||
@ -1534,7 +1535,7 @@ type Table
|
||||
retyped to the `Mixed` type to indicate that intention. Note that the
|
||||
`Mixed` type may not be supported by most Database backends.
|
||||
union : (Table | Vector Table) -> Match_Columns -> Boolean | Report_Unmatched -> Boolean -> Problem_Behavior -> Table
|
||||
union self tables:Vector|Table match_columns=Match_Columns.By_Name keep_unmatched_columns=Report_Unmatched allow_type_widening=True on_problems=Report_Warning =
|
||||
union self tables:(Table | Vector) match_columns=Match_Columns.By_Name keep_unmatched_columns=Report_Unmatched allow_type_widening=True on_problems=Report_Warning =
|
||||
all_tables = case tables of
|
||||
v : Vector -> [self] + (v.map t-> Table.from t)
|
||||
single_table -> [self, single_table]
|
||||
@ -2080,7 +2081,7 @@ type Table
|
||||
_ = [column, pattern, case_sensitivity, parse_values, on_problems]
|
||||
Error.throw (Unsupported_Database_Operation.Error "Table.parse_to_columns is not implemented yet for the Database backends.")
|
||||
|
||||
## GROUP Standard.Base.Conversions
|
||||
## GROUP Standard.Base.Calculations
|
||||
Expand a column of objects to a new set of columns.
|
||||
|
||||
Arguments:
|
||||
@ -2094,7 +2095,7 @@ type Table
|
||||
_ = [column, fields, prefix]
|
||||
Error.throw (Unsupported_Database_Operation.Error "Table.expand_column is currently not implemented for the Database backend. You may download the table to memory using `.read` to use this feature.")
|
||||
|
||||
## GROUP Standard.Base.Conversions
|
||||
## GROUP Standard.Base.Calculations
|
||||
Expand aggregate values in a column to separate rows.
|
||||
|
||||
For each value in the specified column, if it is an aggregate (`Vector`,
|
||||
@ -2190,7 +2191,8 @@ type Table
|
||||
new_column = column_to_cast.cast value_type on_problems
|
||||
table.set new_column new_name=column_to_cast.name set_mode=Set_Mode.Update
|
||||
|
||||
## Change the value type of table columns to a more specific one, based on
|
||||
## GROUP Standard.Base.Conversions
|
||||
Change the value type of table columns to a more specific one, based on
|
||||
their contents.
|
||||
|
||||
This operation is currently not available in the Database backend.
|
||||
@ -2204,15 +2206,15 @@ type Table
|
||||
Remove rows which are all blank or containing blank values.
|
||||
|
||||
Arguments:
|
||||
- when: If Blank_Selector.Any_Cell_Blank, then remove any row containing
|
||||
- when: If Blank_Selector.Any_Cell, then remove any row containing
|
||||
any blank values.
|
||||
If Blank_Selector.All_Cells_Blank, then only remove rows with all blank values.
|
||||
If Blank_Selector.All_Cells, then only remove rows with all blank values.
|
||||
- treat_nans_as_blank: If `True`, then `Number.nan` is considered as blank.
|
||||
|
||||
? Blank values
|
||||
Blank values are `Nothing`, `""` and depending on setting `Number.nan`.
|
||||
filter_blank_rows : Blank_Selector -> Boolean -> Table
|
||||
filter_blank_rows self (when:Blank_Selector = Blank_Selector.All_Cells_Blank) treat_nans_as_blank=False =
|
||||
filter_blank_rows self (when:Blank_Selector = Blank_Selector.All_Cells) treat_nans_as_blank=False =
|
||||
Table_Helpers.filter_blank_rows self when treat_nans_as_blank
|
||||
|
||||
## ALIAS count
|
||||
|
@ -716,6 +716,7 @@ make_date_diff arguments (metadata : Date_Period_Metadata) =
|
||||
as_int64 <|
|
||||
((extract_seconds ++ " * 1000000").paren ++ " + " ++ (micros ++ " % 1000000").paren).paren
|
||||
|
||||
## PRIVATE
|
||||
make_date_trunc_to_day arguments =
|
||||
if arguments.length != 1 then Error.throw (Illegal_State.Error "date_trunc_to_day expects exactly one sub expression. This is a bug in Database library.") else
|
||||
expr = arguments.at 0
|
||||
|
@ -1,6 +1,6 @@
|
||||
from Standard.Base import all
|
||||
|
||||
from project.Errors import SQL_Error, Invariant_Violation
|
||||
from project.Errors import Invariant_Violation, SQL_Error
|
||||
|
||||
## PRIVATE
|
||||
type Postgres_Error_Mapper
|
||||
|
@ -1,6 +1,6 @@
|
||||
from Standard.Base import all
|
||||
|
||||
from project.Errors import SQL_Error, Invariant_Violation
|
||||
from project.Errors import Invariant_Violation, SQL_Error
|
||||
|
||||
polyglot java import org.sqlite.SQLiteErrorCode
|
||||
polyglot java import org.sqlite.SQLiteException
|
||||
|
@ -1,10 +1,10 @@
|
||||
from Standard.Base import all
|
||||
from Standard.Base.Runtime import assert
|
||||
import Standard.Base.Errors.Common.Dry_Run_Operation
|
||||
import Standard.Base.Errors.Common.Forbidden_Operation
|
||||
import Standard.Base.Errors.Illegal_Argument.Illegal_Argument
|
||||
import Standard.Base.Errors.Illegal_State.Illegal_State
|
||||
import Standard.Base.Runtime.Context
|
||||
from Standard.Base.Runtime import assert
|
||||
|
||||
import Standard.Table.Data.Table.Table as In_Memory_Table
|
||||
import Standard.Table.Internal.Problem_Builder.Problem_Builder
|
||||
|
@ -1,6 +1,7 @@
|
||||
## TODO Documents
|
||||
## Specifies the condition for selecting blank cells.
|
||||
type Blank_Selector
|
||||
## Blank_Selector is used as a constructor for other functions.
|
||||
Any_Cell_Blank
|
||||
## Select when any cell is blank or Nothing.
|
||||
Any_Cell
|
||||
|
||||
All_Cells_Blank
|
||||
## Select when all the cells are blank or Nothing.
|
||||
All_Cells
|
||||
|
@ -122,7 +122,7 @@ type Column_Operation
|
||||
|
||||
## PRIVATE
|
||||
Create a widget for operation
|
||||
default_widget : Table_Ref -> Widget
|
||||
default_widget : Table_Ref -> Display -> Widget
|
||||
default_widget table:Table_Ref display=Display.Always =
|
||||
col_refs = Widget_Helpers.make_column_ref_by_name_selector table
|
||||
filter_cond = Widget_Helpers.make_filter_condition_selector table
|
||||
|
@ -1485,7 +1485,7 @@ type Column
|
||||
unusual events like DST.
|
||||
@period Date_Time_Helpers.make_period_selector_for_column
|
||||
date_add : (Column | Integer) -> Date_Period | Time_Period -> Column ! Invalid_Value_Type | Illegal_Argument
|
||||
date_add self amount (period : Date_Period|Time_Period = default_date_period self) =
|
||||
date_add self amount (period : Date_Period | Time_Period = default_date_period self) =
|
||||
Value_Type.expect_type self .is_date_or_time "date/time" <|
|
||||
my_type = self.inferred_precise_value_type
|
||||
Value_Type.expect_integer amount <|
|
||||
@ -1774,7 +1774,8 @@ type Column
|
||||
new_storage = self.java_column.getStorage.cast target_storage_type cast_problem_builder
|
||||
Column.from_storage self.name new_storage
|
||||
|
||||
## Change the value type of the column to a more specific one, based on its
|
||||
## GROUP Standard.Base.Conversions
|
||||
Change the value type of the column to a more specific one, based on its
|
||||
contents.
|
||||
|
||||
Arguments:
|
||||
@ -1845,7 +1846,7 @@ type Column
|
||||
new_st = self.to_vector.map new_fn
|
||||
Column.from_vector self.name new_st value_type=expected_value_type
|
||||
|
||||
## ALIAS combine, merge, join by row position
|
||||
## ALIAS combine, join by row position, merge
|
||||
|
||||
Applies `function` to consecutive pairs of elements of `self` and `that`
|
||||
and returns a column of results.
|
||||
@ -1989,7 +1990,7 @@ type Column
|
||||
- warn_if_more_rows: if set to `True`, a warning is attached to the
|
||||
result if the number of rows returned by the query exceeds `max_rows`.
|
||||
read : (Nothing | Integer) -> Boolean -> Column
|
||||
read self (max_rows : Integer | Nothing = Nothing) (warn_if_more_rows:Boolean = True) =
|
||||
read self (max_rows : Nothing | Integer = Nothing) (warn_if_more_rows:Boolean = True) =
|
||||
if max_rows.is_nothing then self else
|
||||
self.to_table.read max_rows warn_if_more_rows . at 0
|
||||
|
||||
@ -2121,7 +2122,7 @@ type Column
|
||||
sorted = self.to_vector.sort order by=wrapped
|
||||
Column.from_vector self.name sorted
|
||||
|
||||
## ALIAS first, last, slice, sample
|
||||
## ALIAS first, last, sample, slice
|
||||
GROUP Standard.Base.Selections
|
||||
Creates a new Column with the specified range of rows from the input
|
||||
Column.
|
||||
|
@ -414,7 +414,7 @@ type Table
|
||||
|
||||
Arguments:
|
||||
- when: By default, only columns consisting of all blank cells are
|
||||
selected. If set to Blank_Selector.Any_Cell_Blank, columns with one or
|
||||
selected. If set to Blank_Selector.Any_Cell, columns with one or
|
||||
more blank values are selected.
|
||||
- treat_nans_as_blank: specifies whether `Number.nan` is considered as
|
||||
blank. By default, it is not.
|
||||
@ -427,7 +427,7 @@ type Table
|
||||
|
||||
table.select_blank_columns
|
||||
select_blank_columns : Blank_Selector -> Boolean -> Table ! No_Output_Columns
|
||||
select_blank_columns self (when:Blank_Selector = Blank_Selector.All_Cells_Blank) (treat_nans_as_blank : Boolean = False) =
|
||||
select_blank_columns self (when:Blank_Selector = Blank_Selector.All_Cells) (treat_nans_as_blank : Boolean = False) =
|
||||
new_columns = self.columns_helper.select_blank_columns_helper when treat_nans_as_blank
|
||||
if new_columns.length == 0 then Error.throw (No_Output_Columns) else
|
||||
Table.new new_columns
|
||||
@ -440,7 +440,7 @@ type Table
|
||||
|
||||
Arguments:
|
||||
- when By default, only columns consisting of all blank cells are
|
||||
selected. If set to Blank_Selector.Any_Cell_Blank, columns with one or more blank values are
|
||||
selected. If set to Blank_Selector.Any_Cell, columns with one or more blank values are
|
||||
selected.
|
||||
- treat_nans_as_blank: specified whether `Number.nan` is considered as
|
||||
blank. By default, it is not.
|
||||
@ -453,7 +453,7 @@ type Table
|
||||
|
||||
table.remove_blank_columns
|
||||
remove_blank_columns : Blank_Selector -> Boolean -> Table ! No_Output_Columns
|
||||
remove_blank_columns self (when:Blank_Selector = Blank_Selector.All_Cells_Blank) (treat_nans_as_blank : Boolean = False) =
|
||||
remove_blank_columns self (when:Blank_Selector = Blank_Selector.All_Cells) (treat_nans_as_blank : Boolean = False) =
|
||||
new_columns = self.columns_helper.select_blank_columns_helper when treat_nans_as_blank invert_selection=True
|
||||
if new_columns.length == 0 then Error.throw (No_Output_Columns) else
|
||||
Table.new new_columns
|
||||
@ -1116,7 +1116,8 @@ type Table
|
||||
new_column = column_to_cast.cast value_type on_problems
|
||||
table.set new_column new_name=column_to_cast.name set_mode=Set_Mode.Update
|
||||
|
||||
## Change the value type of table columns to a more specific one, based on
|
||||
## GROUP Standard.Base.Conversions
|
||||
Change the value type of table columns to a more specific one, based on
|
||||
their contents.
|
||||
|
||||
This is most useful for `Mixed` type columns and will allow to narrow
|
||||
@ -1271,7 +1272,7 @@ type Table
|
||||
parse_to_columns self column pattern="." case_sensitivity=Case_Sensitivity.Sensitive parse_values=True on_problems=Report_Error =
|
||||
Split_Tokenize.parse_to_columns self column pattern case_sensitivity parse_values on_problems
|
||||
|
||||
## GROUP Standard.Base.Conversions
|
||||
## GROUP Standard.Base.Calculations
|
||||
Expand a column of objects to a new set of columns.
|
||||
|
||||
Arguments:
|
||||
@ -1284,7 +1285,7 @@ type Table
|
||||
expand_column self (column : Text | Integer) (fields : (Vector Text) | Nothing = Nothing) (prefix : Prefix_Name = Prefix_Name.Column_Name) =
|
||||
Expand_Objects_Helpers.expand_column self column fields prefix
|
||||
|
||||
## GROUP Standard.Base.Conversions
|
||||
## GROUP Standard.Base.Calculations
|
||||
Expand aggregate values in a column to separate rows.
|
||||
|
||||
For each value in the specified column, if it is an aggregate (`Vector`,
|
||||
@ -1370,8 +1371,8 @@ type Table
|
||||
people.filter "age" (age -> (age%10 == 0))
|
||||
@column Widget_Helpers.make_column_name_selector
|
||||
@filter Widget_Helpers.make_filter_condition_selector
|
||||
filter : (Column | Text | Integer) -> (Filter_Condition|(Any->Boolean)) -> Problem_Behavior -> Table ! No_Such_Column | Index_Out_Of_Bounds | Invalid_Value_Type
|
||||
filter self column (filter : Filter_Condition | Function = Filter_Condition.Equal True) on_problems=Report_Warning = case column of
|
||||
filter : (Column | Text | Integer) -> (Filter_Condition | (Any -> Boolean)) -> Problem_Behavior -> Table ! No_Such_Column | Index_Out_Of_Bounds | Invalid_Value_Type
|
||||
filter self column (filter : Filter_Condition | (Any -> Boolean) = Filter_Condition.Equal True) on_problems=Report_Warning = case column of
|
||||
_ : Column ->
|
||||
mask filter_column = Table.Value (self.java_table.mask filter_column.java_column)
|
||||
case filter of
|
||||
@ -1567,7 +1568,7 @@ type Table
|
||||
table.set double_inventory new_name="total_stock"
|
||||
table.set "2 * [total_stock]" new_name="total_stock_expr"
|
||||
@column Column_Operation.default_widget
|
||||
set : Text | Column -> Text -> Set_Mode -> Problem_Behavior -> Table ! Existing_Column | Missing_Column | No_Such_Column | Expression_Error
|
||||
set : Text | Column | Constant_Column | Column_Operation -> Text -> Set_Mode -> Problem_Behavior -> Table ! Existing_Column | Missing_Column | No_Such_Column | Expression_Error
|
||||
set self column:(Text | Column | Constant_Column | Column_Operation) (new_name : Text = "") (set_mode : Set_Mode = Set_Mode.Add_Or_Update) (on_problems : Problem_Behavior = Report_Warning) =
|
||||
problem_builder = Problem_Builder.new
|
||||
unique = self.column_naming_helper.create_unique_name_strategy
|
||||
@ -1839,7 +1840,8 @@ type Table
|
||||
self.java_table.crossJoin right.java_table right_prefix java_aggregator
|
||||
Table.Value new_java_table
|
||||
|
||||
## Replaces values in this table by values from a lookup table.
|
||||
## GROUP Standard.Base.Calculations
|
||||
Replaces values in this table by values from a lookup table.
|
||||
New values are looked up in the lookup table based on the `key_columns`.
|
||||
Columns found in the lookup table values are replaced by values from the
|
||||
lookup. Columns not found are left unchanged.
|
||||
@ -2082,7 +2084,7 @@ type Table
|
||||
retyped to the `Mixed` type to indicate that intention. Note that the
|
||||
`Mixed` type may not be supported by most Database backends.
|
||||
union : (Table | Vector Table) -> Match_Columns -> Boolean | Report_Unmatched -> Boolean -> Problem_Behavior -> Table
|
||||
union self tables:Vector|Table match_columns=Match_Columns.By_Name keep_unmatched_columns=Report_Unmatched allow_type_widening=True on_problems=Report_Warning =
|
||||
union self tables:(Table | Vector) match_columns=Match_Columns.By_Name keep_unmatched_columns=Report_Unmatched allow_type_widening=True on_problems=Report_Warning =
|
||||
all_tables = case tables of
|
||||
v : Vector -> [self] + (v.map t-> Table.from t)
|
||||
single_table -> [self, single_table]
|
||||
@ -2105,15 +2107,15 @@ type Table
|
||||
Remove rows which are all blank or containing blank values.
|
||||
|
||||
Arguments:
|
||||
- when: If Blank_Selector.Any_Cell_Blank, then remove any row containing
|
||||
- when: If Blank_Selector.Any_Cell, then remove any row containing
|
||||
any blank values.
|
||||
If Blank_Selector.All_Cells_Blank, then only remove rows with all blank values.
|
||||
If Blank_Selector.All_Cells, then only remove rows with all blank values.
|
||||
- treat_nans_as_blank: If `True`, then `Number.nan` is considered as blank.
|
||||
|
||||
? Blank values
|
||||
Blank values are `Nothing`, `""` and depending on setting `Number.nan`.
|
||||
filter_blank_rows : Blank_Selector -> Boolean -> Table
|
||||
filter_blank_rows self when=Blank_Selector.Any_Cell_Blank treat_nans_as_blank=False =
|
||||
filter_blank_rows self when=Blank_Selector.Any_Cell treat_nans_as_blank=False =
|
||||
Table_Helpers.filter_blank_rows self when treat_nans_as_blank
|
||||
|
||||
## ALIAS count
|
||||
|
@ -209,5 +209,5 @@ type Excel_Workbook
|
||||
- name: the name of the worksheet to read.
|
||||
@name (self-> Single_Choice display=Display.Always values=(self.sheet_names.map t-> Option t t.pretty))
|
||||
sheet : Text | Integer -> Table
|
||||
sheet self name:(Text|Integer) =
|
||||
sheet self name:(Text | Integer) =
|
||||
self.read_section (Excel_Section.Worksheet name 0 Nothing)
|
||||
|
@ -6,7 +6,7 @@ import project.Data.Column_Ref.Column_Ref
|
||||
import project.Data.Expression.Expression_Error
|
||||
import project.Data.Set_Mode.Set_Mode
|
||||
import project.Data.Table.Table
|
||||
from project.Errors import No_Such_Column, Existing_Column, Missing_Column
|
||||
from project.Errors import Existing_Column, Missing_Column, No_Such_Column
|
||||
|
||||
## PRIVATE
|
||||
A helper type allowing to resolve column references in a context of an underlying table.
|
||||
@ -62,8 +62,8 @@ type Table_Ref
|
||||
|
||||
## PRIVATE
|
||||
Set a column.
|
||||
set : Any -> Set_Mode -> Problem_Behavior -> Table_Ref ! Existing_Column | Missing_Column | No_Such_Column | Expression_Error
|
||||
set self column new_name set_mode=Set_Mode.Add_Or_Update on_problems=Report_Warning =
|
||||
set : Any -> Text -> Set_Mode -> Problem_Behavior -> Table_Ref ! Existing_Column | Missing_Column | No_Such_Column | Expression_Error
|
||||
set self column new_name:Text set_mode:Set_Mode=Set_Mode.Add_Or_Update on_problems:Problem_Behavior=Report_Warning =
|
||||
new_underlying = self.underlying.set column new_name set_mode=set_mode on_problems=on_problems
|
||||
Table_Ref.from new_underlying
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
from Standard.Base import all
|
||||
|
||||
## PRIVATE
|
||||
Internal class to represent a constant value as a column.
|
||||
type Constant_Column
|
||||
## PRIVATE
|
||||
Value value:Any
|
||||
|
||||
## PRIVATE
|
||||
|
@ -83,7 +83,7 @@ expand_to_rows table column at_least_one_row=False =
|
||||
Fan_Out.fan_out_to_rows table column row_expander at_least_one_row column_builder=builder
|
||||
|
||||
## PRIVATE
|
||||
create_table_from_objects : Any -> ((Vector Text) | Nothing) -> Table
|
||||
create_table_from_objects : Convertible_To_Rows -> (Vector Text | Nothing) -> Table
|
||||
create_table_from_objects (value : Convertible_To_Rows) (fields : Vector | Nothing) = if fields.is_nothing.not && fields.is_empty then Error.throw (Illegal_Argument.Error "The fields parameter cannot be empty.") else
|
||||
len = value.length
|
||||
|
||||
|
@ -26,7 +26,7 @@ make_double_builder initial_size java_problem_aggregator=(Missing_Required_Argum
|
||||
NumericBuilder.createDoubleBuilder initial_size java_problem_aggregator
|
||||
|
||||
## PRIVATE
|
||||
make_long_builder : Integer -> Bits -> NumericBuilder
|
||||
make_long_builder : Integer -> Bits -> ProblemAggregator -> NumericBuilder
|
||||
make_long_builder initial_size bits java_problem_aggregator=(Missing_Required_Argument.ensure_present "java_problem_aggregator") =
|
||||
integer_type = Storage.from_value_type_strict (Value_Type.Integer bits)
|
||||
NumericBuilder.createLongBuilder initial_size integer_type java_problem_aggregator
|
||||
|
@ -4,7 +4,7 @@ import Standard.Base.Errors.Illegal_Argument.Illegal_Argument
|
||||
import project.Data.Type.Storage
|
||||
import project.Data.Type.Value_Type.Value_Type
|
||||
import project.Data.Type.Value_Type_Helpers
|
||||
from project.Errors import Missing_Input_Columns, Unexpected_Extra_Columns, Floating_Point_Equality, No_Common_Type, No_Output_Columns
|
||||
from project.Errors import Floating_Point_Equality, Missing_Input_Columns, No_Common_Type, No_Output_Columns, Unexpected_Extra_Columns
|
||||
|
||||
polyglot java import org.enso.table.data.table.join.lookup.LookupColumnDescription
|
||||
|
||||
|
@ -199,13 +199,13 @@ type Table_Column_Helper
|
||||
Arguments:
|
||||
-TODO docs
|
||||
- when: By default, only columns consisting of all blank cells are
|
||||
selected. If set to Blank_Selector.Any_Cell_Blank, columns with one or more blank values are
|
||||
selected. If set to Blank_Selector.Any_Cell, columns with one or more blank values are
|
||||
selected.
|
||||
- treat_nans_as_blank: If `True`, then `Number.nan` is considered as
|
||||
blank.
|
||||
- invert_selection: If `True`, then the selection is inverted.
|
||||
select_blank_columns_helper : Blank_Selector -> Boolean -> Boolean -> Vector
|
||||
select_blank_columns_helper self (when:Blank_Selector = Blank_Selector.All_Cells_Blank) treat_nans_as_blank:Boolean invert_selection:Boolean=False =
|
||||
select_blank_columns_helper self (when:Blank_Selector = Blank_Selector.All_Cells) treat_nans_as_blank:Boolean invert_selection:Boolean=False =
|
||||
blanks = self.internal_columns.map_with_index ix-> internal_column->
|
||||
column = self.make_column internal_column
|
||||
blank_indicator = column.is_blank treat_nans_as_blank
|
||||
@ -225,8 +225,8 @@ type Table_Column_Helper
|
||||
|
||||
# Maximum is equivalent to Exists and Minimum is equivalent to Forall.
|
||||
col_aggregate = case when of
|
||||
Blank_Selector.Any_Cell_Blank -> Aggregate_Column.Maximum _
|
||||
Blank_Selector.All_Cells_Blank -> Aggregate_Column.Minimum _
|
||||
Blank_Selector.Any_Cell -> Aggregate_Column.Maximum _
|
||||
Blank_Selector.All_Cells -> Aggregate_Column.Minimum _
|
||||
aggregates = blanks.map blanks_col-> col_aggregate blanks_col.name
|
||||
|
||||
aggregate_result = just_indicators.aggregate aggregates on_problems=Problem_Behavior.Report_Error
|
||||
@ -450,8 +450,8 @@ filter_blank_rows table when treat_nans_as_blank =
|
||||
case cols.not_empty of
|
||||
True ->
|
||||
merge = case when of
|
||||
Blank_Selector.Any_Cell_Blank -> (||)
|
||||
Blank_Selector.All_Cells_Blank -> (&&)
|
||||
Blank_Selector.Any_Cell -> (||)
|
||||
Blank_Selector.All_Cells -> (&&)
|
||||
missing_mask = cols.map (_.is_blank treat_nans_as_blank) . reduce merge
|
||||
non_missing_mask = missing_mask.not
|
||||
table.filter non_missing_mask Filter_Condition.Is_True
|
||||
|
@ -29,14 +29,14 @@ spec setup =
|
||||
table_builder [a, b, c, d, e, f]
|
||||
|
||||
Test.specify "filter_blank_rows should drop rows that contain at least one missing cell" <|
|
||||
d = t0.filter_blank_rows when=Blank_Selector.Any_Cell_Blank
|
||||
d = t0.filter_blank_rows when=Blank_Selector.Any_Cell
|
||||
d.row_count . should_equal 1
|
||||
d.at "a" . to_vector . should_equal [5]
|
||||
d.at "b" . to_vector . should_equal [False]
|
||||
d.at "c" . to_vector . should_equal [" "]
|
||||
|
||||
Test.specify "filter_blank_rows should drop rows that are all blank" <|
|
||||
d2 = t0.filter_blank_rows when=Blank_Selector.All_Cells_Blank
|
||||
d2 = t0.filter_blank_rows when=Blank_Selector.All_Cells
|
||||
d2.at "a" . to_vector . should_equal [0, 1, Nothing, 42, 5]
|
||||
d2.at "b" . to_vector . should_equal [True, Nothing, True, False, False]
|
||||
d2.at "c" . to_vector . should_equal ["", "foo", "bar", Nothing, " "]
|
||||
@ -49,12 +49,12 @@ spec setup =
|
||||
t1.row_count . should_equal 3
|
||||
t1.at "X" . to_vector . should_equal [Nothing, Nothing, Nothing]
|
||||
|
||||
t2 = t1.filter_blank_rows when=Blank_Selector.Any_Cell_Blank
|
||||
t2 = t1.filter_blank_rows when=Blank_Selector.Any_Cell
|
||||
t2.row_count . should_equal 0
|
||||
t2.at "X" . to_vector . should_equal []
|
||||
|
||||
t3 = table_builder [["X", ["", "", Nothing]]]
|
||||
t4 = t3.filter_blank_rows when=Blank_Selector.All_Cells_Blank
|
||||
t4 = t3.filter_blank_rows when=Blank_Selector.All_Cells
|
||||
t4.row_count . should_equal 0
|
||||
t4.at "X" . to_vector . should_equal []
|
||||
|
||||
@ -72,7 +72,7 @@ spec setup =
|
||||
r1.columns.map .name . should_equal ["f"]
|
||||
r1.at "f" . to_vector . should_equal [Nothing, "", Nothing, ""]
|
||||
|
||||
r2 = t1.select_blank_columns when=Blank_Selector.Any_Cell_Blank
|
||||
r2 = t1.select_blank_columns when=Blank_Selector.Any_Cell
|
||||
r2.columns.map .name . should_equal ["a", "b", "d", "e", "f"]
|
||||
r2.at "d" . to_vector . should_equal [Nothing, True, False, True]
|
||||
|
||||
@ -81,7 +81,7 @@ spec setup =
|
||||
r1.columns.map .name . should_equal ["a", "b", "c", "d", "e"]
|
||||
r1.at "a" . to_vector . should_equal [1, Nothing, 3, 4]
|
||||
|
||||
r2 = t1.remove_blank_columns when=Blank_Selector.Any_Cell_Blank
|
||||
r2 = t1.remove_blank_columns when=Blank_Selector.Any_Cell
|
||||
r2.columns.map .name . should_equal ["c"]
|
||||
r2.at "c" . to_vector . should_equal [10, 20, 30, 40]
|
||||
|
||||
@ -93,12 +93,12 @@ spec setup =
|
||||
table_builder [c, g, h]
|
||||
if test_selection.is_nan_and_nothing_distinct then
|
||||
Test.specify "should not treat NaNs as blank by default" <|
|
||||
r1 = t3.filter_blank_rows when=Blank_Selector.Any_Cell_Blank
|
||||
r1 = t3.filter_blank_rows when=Blank_Selector.Any_Cell
|
||||
# We cannot use `Vector.==` because `NaN != NaN`.
|
||||
r1.at "X" . to_vector . to_text . should_equal "[1.5, NaN]"
|
||||
r1.at "Y" . to_vector . should_equal [2.0, 5.0]
|
||||
|
||||
r2 = t3.filter_blank_rows when=Blank_Selector.All_Cells_Blank
|
||||
r2 = t3.filter_blank_rows when=Blank_Selector.All_Cells
|
||||
r2.at "X" . to_vector . to_text . should_equal "[2.0, 1.5, NaN, NaN]"
|
||||
r2.at "Y" . to_vector . should_equal [Nothing, 2.0, Nothing, 5.0]
|
||||
|
||||
@ -106,37 +106,37 @@ spec setup =
|
||||
r3.columns.map .name . should_equal ["c", "g", "h"]
|
||||
r3.at "g" . to_vector . to_text . should_equal "[NaN, 1.0, 2.0, 3.4]"
|
||||
|
||||
r4 = t4.remove_blank_columns when=Blank_Selector.Any_Cell_Blank
|
||||
r4 = t4.remove_blank_columns when=Blank_Selector.Any_Cell
|
||||
r4.columns.map .name . should_equal ["c", "g"]
|
||||
r4.at "g" . to_vector . to_text . should_equal "[NaN, 1.0, 2.0, 3.4]"
|
||||
|
||||
r5 = t4.select_blank_columns when=Blank_Selector.Any_Cell_Blank
|
||||
r5 = t4.select_blank_columns when=Blank_Selector.Any_Cell
|
||||
r5.columns.map .name . should_equal ["h"]
|
||||
r5.at "h" . to_vector . to_text . should_equal "[NaN, Nothing, NaN, Nothing]"
|
||||
|
||||
Test.specify "should allow to treat NaNs as blank if asked" <|
|
||||
r1 = t3.filter_blank_rows when=Blank_Selector.Any_Cell_Blank treat_nans_as_blank=True
|
||||
r1 = t3.filter_blank_rows when=Blank_Selector.Any_Cell treat_nans_as_blank=True
|
||||
# We cannot use `Vector.==` because `NaN != NaN`.
|
||||
r1.at "X" . to_vector . should_equal [1.5]
|
||||
r1.at "Y" . to_vector . should_equal [2.0]
|
||||
|
||||
r2 = t3.filter_blank_rows when=Blank_Selector.All_Cells_Blank treat_nans_as_blank=True
|
||||
r2 = t3.filter_blank_rows when=Blank_Selector.All_Cells treat_nans_as_blank=True
|
||||
r2.at "X" . to_vector . to_text . should_equal "[2.0, 1.5, NaN]"
|
||||
r2.at "Y" . to_vector . should_equal [Nothing, 2.0, 5.0]
|
||||
|
||||
r3 = t4.remove_blank_columns when=Blank_Selector.All_Cells_Blank treat_nans_as_blank=True
|
||||
r3 = t4.remove_blank_columns when=Blank_Selector.All_Cells treat_nans_as_blank=True
|
||||
r3.columns.map .name . should_equal ["c", "g"]
|
||||
r3.at "g" . to_vector . to_text . should_equal "[NaN, 1.0, 2.0, 3.4]"
|
||||
|
||||
r4 = t4.select_blank_columns when=Blank_Selector.All_Cells_Blank treat_nans_as_blank=True
|
||||
r4 = t4.select_blank_columns when=Blank_Selector.All_Cells treat_nans_as_blank=True
|
||||
r4.columns.map .name . should_equal ["h"]
|
||||
r4.at "h" . to_vector . to_text . should_equal "[NaN, Nothing, NaN, Nothing]"
|
||||
|
||||
r5 = t4.remove_blank_columns when=Blank_Selector.Any_Cell_Blank treat_nans_as_blank=True
|
||||
r5 = t4.remove_blank_columns when=Blank_Selector.Any_Cell treat_nans_as_blank=True
|
||||
r5.columns.map .name . should_equal ["c"]
|
||||
r5.at "c" . to_vector . should_equal [10, 20, 40, 30]
|
||||
|
||||
r6 = t4.select_blank_columns when=Blank_Selector.Any_Cell_Blank treat_nans_as_blank=True
|
||||
r6 = t4.select_blank_columns when=Blank_Selector.Any_Cell treat_nans_as_blank=True
|
||||
r6.columns.map .name . should_equal ["g", "h"]
|
||||
r6.at "h" . to_vector . to_text . should_equal "[NaN, Nothing, NaN, Nothing]"
|
||||
|
||||
|
@ -81,10 +81,10 @@ spec =
|
||||
c.to_sql.prepare . should_equal ['SELECT CAST(COALESCE("T1"."B", ?) AS TEXT) AS "B" FROM "T1" AS "T1"', ["not-applicable"]]
|
||||
|
||||
Test.specify "filter_blank_rows should drop rows that contain at least one missing column in a Table" <|
|
||||
t2 = t1.filter_blank_rows when=Blank_Selector.Any_Cell_Blank
|
||||
t2 = t1.filter_blank_rows when=Blank_Selector.Any_Cell
|
||||
t2.to_sql.prepare . should_equal ['SELECT "T1"."A" AS "A", "T1"."B" AS "B", "T1"."C" AS "C" FROM "T1" AS "T1" WHERE (NOT ((("T1"."A" IS NULL) OR (("T1"."B" IS NULL) OR ("T1"."B" = \'\'))) OR ("T1"."C" IS NULL)))', []]
|
||||
|
||||
t3 = t1.filter_blank_rows when=Blank_Selector.All_Cells_Blank
|
||||
t3 = t1.filter_blank_rows when=Blank_Selector.All_Cells
|
||||
t3.to_sql.prepare . should_equal ['SELECT "T1"."A" AS "A", "T1"."B" AS "B", "T1"."C" AS "C" FROM "T1" AS "T1" WHERE (NOT ((("T1"."A" IS NULL) AND (("T1"."B" IS NULL) OR ("T1"."B" = \'\'))) AND ("T1"."C" IS NULL)))', []]
|
||||
|
||||
Test.group "[Codegen] Sorting" <|
|
||||
|
@ -305,7 +305,7 @@ spec =
|
||||
Test.group "Dropping Missing Values" <|
|
||||
Test.specify "should correctly handle NaNs with mixed type columns" <|
|
||||
t = Table.new [["X", [1, 2, 3, 4, 5]], ["Y", ["A", "", Nothing, Number.nan, 0]]]
|
||||
t1 = t.filter_blank_rows when=Blank_Selector.Any_Cell_Blank treat_nans_as_blank=False
|
||||
t1 = t.filter_blank_rows when=Blank_Selector.Any_Cell treat_nans_as_blank=False
|
||||
t1.at "X" . to_vector . should_equal [1, 4, 5]
|
||||
# Comparing text value because `Number.nan != Number.nan`.
|
||||
t1.at "Y" . to_vector . to_text . should_equal "[A, NaN, 0]"
|
||||
@ -314,7 +314,7 @@ spec =
|
||||
c.to_vector . should_equal [False, True, True, True, False]
|
||||
c.value_type . should_equal Value_Type.Boolean
|
||||
|
||||
t2 = t.filter_blank_rows when=Blank_Selector.Any_Cell_Blank treat_nans_as_blank=True
|
||||
t2 = t.filter_blank_rows when=Blank_Selector.Any_Cell treat_nans_as_blank=True
|
||||
t2.at "X" . to_vector . should_equal [1, 5]
|
||||
t2.at "Y" . to_vector . should_equal ['A', 0]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user