Skip to content

Commit

Permalink
feat: Fir 38077 ecosystem support for geography type for net (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
stepansergeevitch authored Dec 4, 2024
1 parent 68847c5 commit 1847ba7
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 4 deletions.
1 change: 1 addition & 0 deletions FireboltDotNetSdk.Tests/FireboltDotNetSdk.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
<PackageReference Include="System.Text.Encodings.Web" Version="4.5.1" />
</ItemGroup>

<ItemGroup>
Expand Down
30 changes: 30 additions & 0 deletions FireboltDotNetSdk.Tests/Integration/ExecuteTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,36 @@ public void ThrowsStructuredExceptionOnJSONErrorBody()
Assert.That(exception.Message, Does.Contain("Unable to cast text 'blue' to integer"));
}

[Test]
[Category("v2")]
[Category("engine-v2")]
public void SelectInsertGeography()
{
var conn = new FireboltConnection(USER_CONNECTION_STRING); conn.Open();
String cleanup = "DROP TABLE IF EXISTS test_geography";
String createTableQuery = "CREATE FACT TABLE test_geography (g GEOGRAPHY)";
String insertQuery = "INSERT INTO test_geography (g) VALUES (@g)";
String selectQuery = "SELECT g FROM test_geography";
String point = "POINT(1 2)";
String pointHex = "0101000020E6100000FEFFFFFFFFFFEF3F0000000000000040";

CreateCommand(conn, cleanup).ExecuteNonQuery();
CreateCommand(conn, createTableQuery).ExecuteNonQuery();
DbCommand insert = CreateCommand(conn, insertQuery);
insert.Prepare();
insert.Parameters.Add(CreateParameter(insert, "@g", point));
insert.ExecuteNonQuery();

DbCommand select = CreateCommand(conn, selectQuery);
using (DbDataReader reader = select.ExecuteReader())
{
Assert.That(reader.Read(), Is.EqualTo(true));
Assert.That(reader.GetString(0), Is.EqualTo(pointHex));
Assert.That(reader.GetFieldType(0), Is.EqualTo(typeof(string)));
Assert.That(reader.Read(), Is.EqualTo(false));
}
}

private void CreateDropFillTableWithArrays(string type1, Array? inta1, Type expType1, string type2, Array? inta2, Type expType2, string type3, Array? inta3, Type expType3)
{
using (var conn = new FireboltConnection(USER_CONNECTION_STRING))
Expand Down
2 changes: 1 addition & 1 deletion FireboltDotNetSdk.Tests/Integration/IntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void SetUp()
{
Database = EnvWithDefault("FIREBOLT_DATABASE");
Endpoint = GetEnvironmentVariable("FIREBOLT_ENDPOINT");
Env = EnvWithDefault("FIREBOLT_ENV", "dev");
Env = EnvWithDefault("FIREBOLT_ENV", "staging");
// Endpoint is not specified by CI/CD (YAML) for v2 where account and engine name are mandatory.
Account = Endpoint == null ? EnvWithDefault("FIREBOLT_ACCOUNT") : GetEnvironmentVariable("FIREBOLT_ACCOUNT");
Engine = Endpoint == null ? EnvWithDefault("FIREBOLT_ENGINE_NAME") : GetEnvironmentVariable("FIREBOLT_ENGINE_NAME");
Expand Down
2 changes: 2 additions & 0 deletions FireboltDotNetSdk.Tests/Unit/ColumnTypeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ public void CreateColumnTypeWithNullableArrayOfArrayTypeTest()
[TestCase("integer null", FireboltDataType.Int, true)]
[TestCase("double null", FireboltDataType.Double, true)]
[TestCase("double", FireboltDataType.Double, false)]
[TestCase("geography", FireboltDataType.Geography, false)]
[TestCase("geography null", FireboltDataType.Geography, true)]
public void CreateColumnTypeWithProvidedColumnTypeNamesTest(String columnTypeName, FireboltDataType expectedType, bool expectedIsNullable)
{
ColumnType columnType = ColumnType.Of(columnTypeName);
Expand Down
4 changes: 3 additions & 1 deletion FireboltNETSDK/Client/FireboltDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public sealed class FireboltDataReader : DbDataReader
private QueryResult _queryResult;
private int _depth;
private int _currentRowIndex = -1;
private const int matchTimeoutSeconds = 60;
private static IDictionary<string, Type> typesMap = new Dictionary<string, Type>(StringComparer.OrdinalIgnoreCase)
{
{ "boolean", typeof(bool) },
Expand All @@ -59,6 +60,7 @@ public sealed class FireboltDataReader : DbDataReader

{ "string", typeof(string) },
{ "text", typeof(string) },
{ "geography", typeof(string) },

{ "date", typeof(DateTime) },
{ "datetime", typeof(DateTime) },
Expand Down Expand Up @@ -281,7 +283,7 @@ private Type GetTypeByName(string typeName)

private string Remove(string str, string regex)
{
return Regex.Replace(str, regex, "", RegexOptions.IgnoreCase);
return Regex.Replace(str, regex, "", RegexOptions.IgnoreCase, TimeSpan.FromSeconds(matchTimeoutSeconds));
}

private bool IsArrayType(string typeName)
Expand Down
1 change: 1 addition & 0 deletions FireboltNETSDK/FireboltDotNetSdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="NodaTime" Version="3.1.6" />
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
<PackageReference Include="System.Text.Encodings.Web" Version="4.5.1" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 6 additions & 2 deletions FireboltNETSDK/Utils/Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System.Globalization;
using System.Text.RegularExpressions;
using FireboltDotNetSdk.Client;
using FireboltDotNetSdk.Exception;
using FireboltDotNetSdk.Utils;
using Newtonsoft.Json;
Expand All @@ -15,13 +16,14 @@ namespace FireboltDoNetSdk.Utils
public enum FireboltDataType
{
String, Long, Int, Float, Double, Null, Decimal, Date, DateTime, TimestampNtz, TimestampTz,
Boolean, Array, Short, ByteA
Boolean, Array, Short, ByteA, Geography
}
public static class TypesConverter
{

//Regex that matches the string Nullable(<type>), where type is the type that we need to capture.
private const string NullableTypePattern = @"Nullable\(([^)]+)\)";
private const int matchTimeoutSeconds = 60;
internal static IDictionary<string, double> doubleInfinity = new Dictionary<string, double>(StringComparer.OrdinalIgnoreCase)
{
{ "inf", double.PositiveInfinity },
Expand Down Expand Up @@ -66,6 +68,7 @@ public static class TypesConverter
case FireboltDataType.Decimal:
return Convert.ToDecimal(str.Trim('"'));
case FireboltDataType.String:
case FireboltDataType.Geography:
return str;
case FireboltDataType.DateTime:
case FireboltDataType.TimestampTz:
Expand Down Expand Up @@ -145,14 +148,15 @@ public static FireboltDataType MapColumnTypeToFireboltDataType(string columnType
"boolean" => FireboltDataType.Boolean,
"array" => FireboltDataType.Array,
"bytea" => FireboltDataType.ByteA,
"geography" => FireboltDataType.Geography,
_ => throw new FireboltException("The data type returned from the server is not supported: " + columnType),
};
return csharpType;
}

public static string GetFullColumnTypeName(Meta meta)
{
Match nullableMatch = Regex.Match(meta.Type, NullableTypePattern);
Match nullableMatch = Regex.Match(meta.Type, NullableTypePattern, RegexOptions.None, TimeSpan.FromSeconds(matchTimeoutSeconds));
var type = nullableMatch.Success ? nullableMatch.Groups[1].Value : meta.Type;
return type;
}
Expand Down

0 comments on commit 1847ba7

Please sign in to comment.