Hiperspace.SQL
2.0.0
dotnet add package Hiperspace.SQL --version 2.0.0
NuGet\Install-Package Hiperspace.SQL -Version 2.0.0
<PackageReference Include="Hiperspace.SQL" Version="2.0.0" />
paket add Hiperspace.SQL --version 2.0.0
#r "nuget: Hiperspace.SQL, 2.0.0"
// Install Hiperspace.SQL as a Cake Addin #addin nuget:?package=Hiperspace.SQL&version=2.0.0 // Install Hiperspace.SQL as a Cake Tool #tool nuget:?package=Hiperspace.SQL&version=2.0.0
Hiperspace.SQL
Hiperspace.SQL is a full SQL query engine for Hiperspace, supporting the full range of joins, aggregations, and subqueries.
Hiperspace.SQL provides the same query functionality as a .NET client can use with LINQ queries, but without the need to write code in C#/F#
Hiperspace fully supports point-in-time "time travel" queries that are not possible with Python Data-Frames or DuckDB
Features
- Hiperspace.SQL is not limited to queries of columns within a table, but supports the full navigation of properties of Hiperspace elements
- Where a column is a complex object it is returned as a JSON object
- Executing a batch of SQL statements return columnar data frames (dictionary of column-name and array of values)
- Explain SQL returns the execution plan, detailing the SetSPaces accessed and keys used for search (Key, Index, Scan)
- The Parquet method returns a Parquet file that can be used with any Apache Parquet library, or added to DuckDB OLAP store
Data Dictionary
SCHEMA_TABLE
Column Name | Data Type | Description |
---|---|---|
TABLE_NAME | string | The name of the table |
TABLE_TYPE | string | The type of the table in SCHEMA_PROPERTY |
SCHEMA_COLUMN
Column Name | Data Type | Description |
---|---|---|
TABLE_NAME | string | The name of the table |
COLUMN_NAME | string | The name of the column |
COLUMN_TYPE | string | The type of the table in SCHEMA_PROPERTY |
SCHEMA_PROPERTY
Column Name | Data Type | Description |
---|---|---|
TYPE_NAME | string | The Type Name |
PROPERTY_NAME | string | The name of each property |
PROPERTY_TYPE | string | reference to SCHEMA_PROPERTY.TYPE_NAME |
Examples
Simple query
SELECT p.Name, p.Gender FROM Persons as p WHERE p.Name = 'Lucy'
Query parameters
SELECT p.Name, p.Gender FROM Persons as p WHERE p.Name = :name
Query batches
SELECT p.Name, p.Gender FROM Persons as p WHERE p.Name = :name;
SELECT Name as name, Father as father from Persons ;
Joins
SELECT p.Name, f.Name as Father, f.Father as GrandFather
FROM Persons as p
join Persons as f on p.Father.Name = f.Name
WHERE p.Name = :name
Aggregates
select p.Father.Name, count(p.Name) as Children
from Persons as p
group by p.Father.Name as f
having count(*) > 1;
Like expressions
select p.Father.Name, count(p.Name) as Children
from Persons as p
where Name like 'L%' and Name like '%y' or (Name like '%u%' and Name like '_uc_')
group by p.Father.Name as f
having count(*) > 1;
Null handling
select p.Name, p.Father.Name
from Persons as p
where Name is not null
in query
SELECT p.Name, p.Gender
FROM Persons as p
WHERE p.Gender in (select p2.Gender from Persons as p2 where p2.Name = 'Lucy')
union
SELECT p.Name, p.Gender
FROM Persons as p
WHERE p.Name in ('Lucy', 'Mark')
union
SELECT p.Name, p.Gender
FROM Persons as p
WHERE p.Name in ('Eve', 'Mary')
inline view
SELECT p.Name, p.Gender
FROM Persons as p
join (select p2.Gender from Persons as p2 where p2.Name = 'Lucy') as p3 on p.Gender = p3.Gender
dictionary query
select * from SCHEMA_TABLES;
select * from SCHEMA_COLUMNS;
select * from SCHEMA_PROPERTIES;
API
The Hiperspace.SQL API can be called from any language that supports DOTNET interop, including Python (using pythonnet). Access via the Hiperspace.SQL.Engine object that is constructed with a reference to any domain space.
Explain
Provides a detailed breakdown of the query execution plan
member engine.Explain (source, parameters : IDictionary<string,obj>) : string array =
Execute
Executes the SQL queries and returns an array of Data Frames
member engine.Execute (source , parameters : IDictionary<string,obj>) : IDictionary<string, obj array> array =
Parquet
Executes the SQL queries will a n array of filenames (one for each statement) and returns the filenames after writing the results to the Apache Parquet files.
member this.Parquet (source, fileNames, parameters : IDictionary<string,obj>): string array =
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net8.0
- FSharp.Core (>= 9.0.100)
- FsLexYacc (>= 11.3.0)
- FsLexYacc.Runtime (>= 11.3.0)
- Hiperspace (>= 2.0.0)
- Microsoft.Bcl.HashCode (>= 6.0.0)
- Microsoft.CodeAnalysis (>= 4.11.0)
- Microsoft.CodeAnalysis.Analyzers (>= 3.11.0)
- Microsoft.CodeAnalysis.CSharp (>= 4.11.0)
- Nerdbank.GitVersioning (>= 3.6.146)
- Parquet.Net (>= 5.0.2)
- protobuf-net.Core (>= 3.2.45)
- System.CodeDom (>= 9.0.0)
- System.Text.Json (>= 9.0.0)
-
net9.0
- FSharp.Core (>= 9.0.100)
- FsLexYacc (>= 11.3.0)
- FsLexYacc.Runtime (>= 11.3.0)
- Hiperspace (>= 2.0.0)
- Microsoft.Bcl.HashCode (>= 6.0.0)
- Microsoft.CodeAnalysis (>= 4.11.0)
- Microsoft.CodeAnalysis.Analyzers (>= 3.11.0)
- Microsoft.CodeAnalysis.CSharp (>= 4.11.0)
- Nerdbank.GitVersioning (>= 3.6.146)
- Parquet.Net (>= 5.0.2)
- protobuf-net.Core (>= 3.2.45)
- System.CodeDom (>= 9.0.0)
- System.Text.Json (>= 9.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
## Overview
This Version is a major refactor, taking into consideration lessons learned from implementing hyperspace with blazer web assembly. It was hoped that .NET 9 would include greater compatibility with runtime type creation (used by protobuf-net for serialisation classes) or that protobuf-net "Ahead of time" (AOT) code generation would be included, but switching to direct protobuf serialization has the additional benefit of simplify usage with {Android, iOS, [Unity](https://unity.com/), zOS, [Meadow](https://www.wildernesslabs.co/)}. **Hiperspace** is the only domain-oriented object mapping technology that can be deployed into these environments, providing transparent sharing of elements between edge devices and server context.
The companion change to [HiLang](HiLang) includes the generation of serialization code for domain models.
### Security enhancement
Previously the predicates provided to **Horizon** filters look an instance of an element and return true if it was within the horizon of the subspace. This has been expanded to allow three types of Horizon Filter
* `new Horizon<Element_Type> ( element => element.Valid == true)' a horizon predicate with the element only
* `new Horizon<Element_Type> ( (element, read) => element.Valid == true || read)' a horizon predicate with a flag to indicate a read operation
* `new Horizon<Element_Type> ( (element, context, read) => element.Valid == true || read)' a horizon predicate with a context parameter and a flag to indicate a read operation
* `new Horizon<Element_Type> ( (element, context, user, read) => element.Valid == true || user?.IsInRole("BULK"))' a horizon predicate with a context parameter, user IPrinciple and a flag to indicate a read operation
Subspace has three labels added to support enhanced security
| Label name | Description |
| ------------- | ------------- |
| Context | Context that the space was opened with e.g. "Front Office", "Risk", "Settlement" |
| User | an optional `IPrincipal` for access control |
| Remote | Was the subspace opened remotely, and security/validation need to be re-applied on the server |
### Protobuf-net
[protobuf-net](protobuf-net) dependency for all .NET assemblies have been changed to [protobuf-net.Core](protobuf-net.Core) which does not include dynamic generation of serialization/deserialization code.
### Web applications
Web applications can take advantage of the HiperSpace shared between the web-client (or desktop applications) and the server session for the user with full lazy loading as required.
Hiperspace elements are transferred using [gRPC-Web](https://github.com/grpc/grpc-web) for web-clients {browser, Android, iOS, [Unity](https://unity.com/)} and [gRPC](https://grpc.io/) for desktop applications.
gRPC-Web packets are exchanged space efficient binary messages without JSON text conversion