-
Notifications
You must be signed in to change notification settings - Fork 9
Npgsql: Add software tests validating all data types of CrateDB #772
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ac6add0
Npgsql: Improve SystemQueryExample
amotl ba86c9b
Npgsql: Add test validating (almost) all data types of CrateDB
amotl 1c36aa2
Npgsql: Validate marshalling OBJECT types as STRING, and query it
amotl 3cf3d1a
Npgsql: Validate marshalling GEO_SHAPE types as STRING
amotl 5fe5f6d
Npgsql: Activate previously deactivated validation for float and double
amotl 0508913
Npgsql: Add tracking link to FIXME item
amotl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,249 @@ | ||
#nullable enable | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using Newtonsoft.Json; | ||
using Npgsql; | ||
using NpgsqlTypes; | ||
|
||
namespace demo | ||
{ | ||
|
||
public class AllTypesRecord | ||
{ | ||
[JsonProperty("null_integer", NullValueHandling = NullValueHandling.Ignore)] | ||
public int? NullInteger { get; set; } | ||
[JsonProperty("integer")] | ||
public int? Integer { get; set; } | ||
[JsonProperty("bigint")] | ||
public long? Bigint { get; set; } | ||
[JsonProperty("float")] | ||
public float? Float { get; set; } | ||
[JsonProperty("double")] | ||
public double? Double { get; set; } | ||
[JsonProperty("decimal")] | ||
public decimal? Decimal { get; set; } | ||
//[JsonProperty("bit")] | ||
//public BitArray Bit { get; set; } | ||
[JsonProperty("bool")] | ||
public bool? Bool { get; set; } | ||
[JsonProperty("text")] | ||
public string? Text { get; set; } | ||
[JsonProperty("char")] | ||
public string? Char { get; set; } | ||
[JsonProperty("timestamp_tz")] | ||
public string? Timestamp { get; set; } | ||
[JsonProperty("timestamp_notz")] | ||
public string? TimestampNoTz { get; set; } | ||
[JsonProperty("ip")] | ||
public string? Ip { get; set; } | ||
|
||
[JsonProperty("array")] | ||
public IList<string>? Array { get; set; } | ||
[JsonProperty("object")] | ||
public Dictionary<string, string>? Object { get; set; } | ||
[JsonProperty("geopoint")] | ||
public Dictionary<string, double>? Geopoint { get; set; } | ||
[JsonProperty("geoshape")] | ||
public Dictionary<string, string>? Geoshape { get; set; } | ||
[JsonProperty("float_vector")] | ||
public IList<string>? FloatVector { get; set; } | ||
} | ||
|
||
public class DatabaseWorkloadsMore | ||
{ | ||
|
||
public static async Task<DataTable> AllTypesExample(NpgsqlConnection conn) | ||
{ | ||
Console.WriteLine("Running AllTypesExample"); | ||
|
||
// Submit DDL, create database schema. | ||
await using (var cmd = new NpgsqlCommand("DROP TABLE IF EXISTS testdrive.example", conn)) | ||
{ | ||
cmd.ExecuteNonQuery(); | ||
} | ||
|
||
await using (var cmd = new NpgsqlCommand(@" | ||
CREATE TABLE testdrive.example ( | ||
-- Numeric types | ||
null_integer INT, | ||
integer INT, | ||
bigint BIGINT, | ||
float FLOAT, | ||
double DOUBLE, | ||
decimal DECIMAL(8, 2), | ||
-- Other scalar types | ||
bit BIT(8), | ||
bool BOOLEAN, | ||
text TEXT, | ||
char CHARACTER(5), | ||
timestamp_tz TIMESTAMP WITH TIME ZONE, | ||
timestamp_notz TIMESTAMP WITHOUT TIME ZONE, | ||
ip IP, | ||
-- Container types | ||
""array"" ARRAY(STRING), | ||
""object"" OBJECT(DYNAMIC), | ||
-- Geospatial types | ||
geopoint GEO_POINT, | ||
geoshape GEO_SHAPE, | ||
-- Vector type | ||
""float_vector"" FLOAT_VECTOR(3) | ||
); | ||
", conn)) | ||
{ | ||
cmd.ExecuteNonQuery(); | ||
} | ||
|
||
// Insert single data point. | ||
await using (var cmd = new NpgsqlCommand(@" | ||
INSERT INTO testdrive.example ( | ||
null_integer, | ||
integer, | ||
bigint, | ||
float, | ||
double, | ||
decimal, | ||
bit, | ||
bool, | ||
text, | ||
char, | ||
timestamp_tz, | ||
timestamp_notz, | ||
ip, | ||
""array"", | ||
""object"", | ||
geopoint, | ||
geoshape, | ||
float_vector | ||
) VALUES ( | ||
@null_integer, | ||
@integer, | ||
@bigint, | ||
@float, | ||
@double, | ||
@decimal, | ||
@bit, | ||
@bool, | ||
@text, | ||
@char, | ||
@timestamp_tz, | ||
@timestamp_notz, | ||
@ip, | ||
@array, | ||
@object, | ||
@geopoint, | ||
@geoshape, | ||
@float_vector | ||
); | ||
", conn)) | ||
{ | ||
Console.WriteLine(cmd); | ||
cmd.Parameters.AddWithValue("null_integer", DBNull.Value); | ||
cmd.Parameters.AddWithValue("integer", 42); | ||
cmd.Parameters.AddWithValue("bigint", 42); | ||
cmd.Parameters.AddWithValue("float", 42.42); | ||
cmd.Parameters.AddWithValue("double", 42.42); | ||
cmd.Parameters.AddWithValue("decimal", 42.42); | ||
cmd.Parameters.AddWithValue("bit", "01010101"); | ||
cmd.Parameters.AddWithValue("bool", true); | ||
cmd.Parameters.AddWithValue("text", "foobar"); | ||
cmd.Parameters.AddWithValue("char", "foo"); | ||
cmd.Parameters.AddWithValue("timestamp_tz", "1970-01-02T00:00:00+01:00"); | ||
cmd.Parameters.AddWithValue("timestamp_notz", "1970-01-02T00:00:00"); | ||
cmd.Parameters.AddWithValue("ip", "127.0.0.1"); | ||
cmd.Parameters.AddWithValue("array", new List<string>{"foo", "bar"}); | ||
// FIXME: System.NotSupportedException: Cannot resolve 'hstore' to a fully qualified datatype name. The datatype was not found in the current database info. | ||
// https://github.com/crate/zk/issues/26 | ||
// cmd.Parameters.AddWithValue("object", new Dictionary<string, string>(){{"foo", "bar"}}); | ||
cmd.Parameters.AddWithValue("object", @"{""foo"": ""bar""}"); | ||
cmd.Parameters.AddWithValue("geopoint", new List<double>{85.43, 66.23}); | ||
cmd.Parameters.AddWithValue("geoshape", "POLYGON ((5 5, 10 5, 10 10, 5 10, 5 5))"); | ||
cmd.Parameters.AddWithValue("float_vector", new List<double> {1.1, 2.2, 3.3}); | ||
cmd.ExecuteNonQuery(); | ||
} | ||
|
||
// Flush data. | ||
await using (var cmd = new NpgsqlCommand("REFRESH TABLE testdrive.example", conn)) | ||
{ | ||
cmd.ExecuteNonQuery(); | ||
} | ||
|
||
// Query back data. | ||
await using (var cmd = new NpgsqlCommand("SELECT * FROM testdrive.example", conn)) | ||
await using (var reader = cmd.ExecuteReader()) | ||
{ | ||
var dataTable = new DataTable(); | ||
dataTable.Load(reader); | ||
var payload = JsonConvert.SerializeObject(dataTable); | ||
Console.WriteLine(payload); | ||
return (DataTable) dataTable; | ||
} | ||
|
||
} | ||
|
||
public static async Task<DataTable> ContainerTypesExample(NpgsqlConnection conn) | ||
{ | ||
Console.WriteLine("Running AllTypesExample"); | ||
|
||
// Submit DDL, create database schema. | ||
await using (var cmd = new NpgsqlCommand("DROP TABLE IF EXISTS testdrive.container", conn)) | ||
{ | ||
cmd.ExecuteNonQuery(); | ||
} | ||
|
||
await using (var cmd = new NpgsqlCommand(@" | ||
CREATE TABLE testdrive.container ( | ||
-- Container types | ||
""array"" ARRAY(STRING), | ||
""object"" OBJECT(DYNAMIC) | ||
); | ||
", conn)) | ||
{ | ||
cmd.ExecuteNonQuery(); | ||
} | ||
|
||
// Insert single data point. | ||
await using (var cmd = new NpgsqlCommand(@" | ||
INSERT INTO testdrive.container ( | ||
""array"", | ||
""object"" | ||
) VALUES ( | ||
@array, | ||
@object | ||
); | ||
", conn)) | ||
{ | ||
Console.WriteLine(cmd); | ||
// FIXME: While doing conversations with ARRAY types works natively, | ||
// it doesn't work for OBJECT types. | ||
// Yet, they can be submitted as STRING in JSON format. | ||
cmd.Parameters.AddWithValue("array", new List<string>{"foo", "bar"}); | ||
cmd.Parameters.AddWithValue("object", @"{""foo"": ""bar""}"); | ||
cmd.ExecuteNonQuery(); | ||
} | ||
|
||
// Flush data. | ||
await using (var cmd = new NpgsqlCommand("REFRESH TABLE testdrive.container", conn)) | ||
{ | ||
cmd.ExecuteNonQuery(); | ||
} | ||
|
||
// Query back data. | ||
await using (var cmd = new NpgsqlCommand("SELECT * FROM testdrive.container", conn)) | ||
await using (var reader = cmd.ExecuteReader()) | ||
{ | ||
var dataTable = new DataTable(); | ||
dataTable.Load(reader); | ||
var payload = JsonConvert.SerializeObject(dataTable); | ||
Console.WriteLine(payload); | ||
return (DataTable) dataTable; | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
} |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 am not sure about those, because apparently, they work in this context, but it is also just a very basic test anyway. Let me reference this report, to have a complete list of evalations here, and to reduce the surface of unknown unknowns.
It might indicate a flaw we may investigate closer and possibly resolve while modernizing the driver.