From f8d5b0f2330dc90e043ae4e713ddfde43ac723c6 Mon Sep 17 00:00:00 2001 From: Lucy Zhang Date: Thu, 12 Jan 2023 09:35:20 -0800 Subject: [PATCH 01/13] get started on adding datatypes --- test-outofproc/Product.cs | 47 +++- test/Common/ProductColumnTypes.cs | 49 ++++- test/Database/Tables/ProductsColumnTypes.sql | 28 ++- .../SqlInputBindingIntegrationTests.cs | 30 ++- .../test-csharp/AddProductColumnTypes.cs | 26 ++- .../com/function/AddProductColumnTypes.java | 8 +- .../function/Common/ProductColumnTypes.java | 201 +++++++++++++++++- .../test-js/AddProductColumnTypes/index.js | 20 +- .../AddProductColumnTypes/run.ps1 | 24 ++- .../AddProductColumnTypes/__init__.py | 7 +- 10 files changed, 413 insertions(+), 27 deletions(-) diff --git a/test-outofproc/Product.cs b/test-outofproc/Product.cs index 16768cd42..868d43352 100644 --- a/test-outofproc/Product.cs +++ b/test-outofproc/Product.cs @@ -93,24 +93,67 @@ public static List GetNewProductsRandomized(int num, int cost) return products; } } + public class ProductColumnTypes { public int ProductId { get; set; } + public long BigInt { get; set; } + + public bool Bit { get; set; } + + public decimal DecimalType { get; set; } + + public decimal Money { get; set; } + + public decimal Numeric { get; set; } + + public short SmallInt { get; set; } + + public decimal SmallMoney { get; set; } + + public short TinyInt { get; set; } + + public Double FloatType { get; set; } + + public Single Real { get; set; } + + public DateTime Date { get; set; } + public DateTime Datetime { get; set; } public DateTime Datetime2 { get; set; } + public DateTimeOffset DatetimeOffset { get; set; } + + public DateTime SmallDatetime { get; set; } + + public TimeSpan Time { get; set; } + + public string CharType { get; set; } + + public string Varchar { get; set; } + + public string Nchar { get; set; } + + public string Nvarchar { get; set; } + public override bool Equals(object obj) { if (obj is ProductColumnTypes) { var that = obj as ProductColumnTypes; - return this.ProductId == that.ProductId && this.Datetime == that.Datetime && this.Datetime2 == that.Datetime2; + return this.ProductId == that.ProductId && this.BigInt == that.BigInt && this.Bit == that.Bit && + this.DecimalType == that.DecimalType && this.Money == that.Money && this.Numeric == that.Numeric && + this.SmallInt == that.SmallInt && this.SmallMoney == that.SmallMoney && this.TinyInt == that.TinyInt && + this.FloatType == that.FloatType && this.Real == that.Real && this.Date == that.Date && + this.Datetime == that.Datetime && this.Datetime2 == that.Datetime2 && this.DatetimeOffset == that.DatetimeOffset && + this.SmallDatetime == that.SmallDatetime && this.Time == that.Time && this.CharType == that.CharType && + this.Varchar == that.Varchar && this.Nchar == that.Nchar && this.Nvarchar == that.Nvarchar; } return false; } - } + public class ProductExtraColumns { public int ProductId { get; set; } diff --git a/test/Common/ProductColumnTypes.cs b/test/Common/ProductColumnTypes.cs index 7a8bd88be..1be1eca55 100644 --- a/test/Common/ProductColumnTypes.cs +++ b/test/Common/ProductColumnTypes.cs @@ -9,18 +9,65 @@ public class ProductColumnTypes { public int ProductId { get; set; } + public long BigInt { get; set; } + + public bool Bit { get; set; } + + public decimal DecimalType { get; set; } + + public decimal Money { get; set; } + + public decimal Numeric { get; set; } + + public short SmallInt { get; set; } + + public decimal SmallMoney { get; set; } + + public short TinyInt { get; set; } + + public Double FloatType { get; set; } + + public Single Real { get; set; } + + public DateTime Date { get; set; } + public DateTime Datetime { get; set; } public DateTime Datetime2 { get; set; } + public DateTimeOffset DatetimeOffset { get; set; } + + public DateTime SmallDatetime { get; set; } + + public TimeSpan Time { get; set; } + + public string CharType { get; set; } + + public string Varchar { get; set; } + + public string Nchar { get; set; } + + public string Nvarchar { get; set; } + public override bool Equals(object obj) { if (obj is ProductColumnTypes) { var that = obj as ProductColumnTypes; - return this.ProductId == that.ProductId && this.Datetime == that.Datetime && this.Datetime2 == that.Datetime2; + return this.ProductId == that.ProductId && this.BigInt == that.BigInt && this.Bit == that.Bit && + this.DecimalType == that.DecimalType && this.Money == that.Money && this.Numeric == that.Numeric && + this.SmallInt == that.SmallInt && this.SmallMoney == that.SmallMoney && this.TinyInt == that.TinyInt && + this.FloatType == that.FloatType && this.Real == that.Real && this.Date == that.Date && + this.Datetime == that.Datetime && this.Datetime2 == that.Datetime2 && this.DatetimeOffset == that.DatetimeOffset && + this.SmallDatetime == that.SmallDatetime && this.Time == that.Time && this.CharType == that.CharType && + this.Varchar == that.Varchar && this.Nchar == that.Nchar && this.Nvarchar == that.Nvarchar; } return false; } + + public override string ToString() + { + return $"[{this.ProductId}, {this.BigInt}, {this.Bit}, {this.DecimalType}, {this.Money}, {this.Numeric}, {this.SmallInt}, {this.SmallMoney}, {this.TinyInt}, {this.FloatType}, {this.Real}, {this.Date}, {this.Datetime}, {this.Datetime2}, {this.DatetimeOffset}, {this.SmallDatetime}, {this.Time}, {this.CharType}, {this.Varchar}, {this.Nchar}, {this.Nvarchar}]"; + } } } diff --git a/test/Database/Tables/ProductsColumnTypes.sql b/test/Database/Tables/ProductsColumnTypes.sql index a552b9db1..568ad7f02 100644 --- a/test/Database/Tables/ProductsColumnTypes.sql +++ b/test/Database/Tables/ProductsColumnTypes.sql @@ -1,5 +1,25 @@ CREATE TABLE [ProductsColumnTypes] ( - [ProductId] [int] NOT NULL PRIMARY KEY, - [Datetime] [datetime], - [Datetime2] [datetime2] -) \ No newline at end of file + [ProductId] [int] NOT NULL PRIMARY KEY, + [BigInt] [bigint], + [Bit] [bit], + [DecimalType] [decimal](18,4), + [Money] [money], + [Numeric] [numeric](18,4), + [SmallInt] [smallint], + [SmallMoney] [smallmoney], + [TinyInt] [tinyint], + [FloatType] [float], + [Real] [real], + [Date] [date], + [Datetime] [datetime], + [Datetime2] [datetime2], + [DatetimeOffset] [datetimeoffset], + [SmallDatetime] [smalldatetime], + [Time] [time], + [CharType] [char](4), + [Varchar] [varchar](100), + [Nchar] [nchar](4), + [Nvarchar] [nvarchar](100), + -- [Binary] [binary], + -- [Varbinary] [varbinary] +) diff --git a/test/Integration/SqlInputBindingIntegrationTests.cs b/test/Integration/SqlInputBindingIntegrationTests.cs index c47416bd5..a2c65d7f7 100644 --- a/test/Integration/SqlInputBindingIntegrationTests.cs +++ b/test/Integration/SqlInputBindingIntegrationTests.cs @@ -175,15 +175,35 @@ public async void GetProductsColumnTypesSerializationTest(SupportedLanguages lan string datetime = "2022-10-20 12:39:13.123"; this.ExecuteNonQuery("INSERT INTO [dbo].[ProductsColumnTypes] VALUES (" + - "999, " + // ProductId - $"CONVERT(DATETIME, '{datetime}'), " + // Datetime field - $"CONVERT(DATETIME2, '{datetime}'))"); // Datetime2 field + "999, " + // ProductId, + "999, " + // BigInt + "1, " + // Bit + "1.2345, " + // DecimalType + "1.2345, " + // Money + "1.2345, " + // Numeric + "1, " + // SmallInt + "1.2345, " + // SmallMoney + "1, " + // TinyInt + ".1, " + // FloatType + ".1, " + // Real + $"CONVERT(DATE, '{datetime}'), " + // Date + $"CONVERT(DATETIME, '{datetime}'), " + // Datetime + $"CONVERT(DATETIME2, '{datetime}'), " + // Datetime2 + $"CONVERT(DATETIMEOFFSET, '{datetime}'), " + // DatetimeOffSet + $"CONVERT(SMALLDATETIME, '{datetime}'), " + // SmallDatetime + $"CONVERT(TIME, '{datetime}'), " + // Time + "'test', " + // CharType + "'test', " + // Varchar + "'test', " + // Nchar + "'test')"); // Nvarchar HttpResponseMessage response = await this.SendInputRequest("getproducts-columntypesserialization"); - // We expect the datetime and datetime2 fields to be returned in UTC format - ProductColumnTypes[] expectedResponse = JsonConvert.DeserializeObject("[{\"ProductId\":999,\"Datetime\":\"2022-10-20T12:39:13.123Z\",\"Datetime2\":\"2022-10-20T12:39:13.123Z\"}]"); + // We expect the date fields to be returned in UTC format + ProductColumnTypes[] expectedResponse = JsonConvert.DeserializeObject("[{\"ProductId\":999,\"BigInt\":999,\"Bit\":true,\"DecimalType\":1.2345,\"Money\":1.2345,\"Numeric\":1.2345,\"SmallInt\":1,\"SmallMoney\":1.2345,\"TinyInt\":1,\"FloatType\":0.1,\"Real\":0.1,\"Date\":\"2022-10-20T00:00:00.000Z\",\"Datetime\":\"2022-10-20T12:39:13.123Z\",\"Datetime2\":\"2022-10-20T12:39:13.123Z\",\"DatetimeOffset\":\"2022-10-20T12:39:13.123Z\",\"SmallDatetime\":\"2022-10-20T12:39:00.000Z\",\"Time\":\"12:39:13.1230000\",\"CharType\":\"test\",\"Varchar\":\"test\",\"Nchar\":\"test\",\"Nvarchar\":\"test\"}]"); string actualResponse = await response.Content.ReadAsStringAsync(); ProductColumnTypes[] actualProductResponse = JsonConvert.DeserializeObject(actualResponse); + Console.WriteLine(expectedResponse[0].ToString()); + Console.WriteLine(actualProductResponse[0].ToString()); Assert.Equal(expectedResponse, actualProductResponse); } diff --git a/test/Integration/test-csharp/AddProductColumnTypes.cs b/test/Integration/test-csharp/AddProductColumnTypes.cs index 79fa416f9..7eb53bf76 100644 --- a/test/Integration/test-csharp/AddProductColumnTypes.cs +++ b/test/Integration/test-csharp/AddProductColumnTypes.cs @@ -13,7 +13,7 @@ public static class AddProductColumnTypes { /// /// This function is used to test compatability with converting various data types to their respective - /// SQL server types. + /// SQL server types. /// [FunctionName(nameof(AddProductColumnTypes))] public static IActionResult Run( @@ -23,8 +23,28 @@ public static IActionResult Run( product = new ProductColumnTypes() { ProductId = int.Parse(req.Query["productId"]), - Datetime = DateTime.UtcNow, - Datetime2 = DateTime.UtcNow + BigInt = int.MaxValue, + Bit = true, + DecimalType = 1.2345M, + Money = 1.23M, + Numeric = 1.2345M, + SmallInt = 0, + SmallMoney = 1.23M, + TinyInt = 1, + FloatType = 1.2, + Real = 1.2f, + Date = DateTime.Now, + Datetime = DateTime.Now, + Datetime2 = DateTime.Now, + DatetimeOffset = DateTime.Now, + SmallDatetime = DateTime.Now, + Time = DateTime.Now.TimeOfDay, + CharType = "test", + Varchar = "test", + Nchar = "test", + Nvarchar = "test", + // Binary = new byte[] { 1, 2, 3 }, + // Varbinary = new byte[] { 1, 2, 3 } }; // Items were inserted successfully so return success, an exception would be thrown if there diff --git a/test/Integration/test-java/src/main/java/com/function/AddProductColumnTypes.java b/test/Integration/test-java/src/main/java/com/function/AddProductColumnTypes.java index c95a21f4c..431cbd12a 100644 --- a/test/Integration/test-java/src/main/java/com/function/AddProductColumnTypes.java +++ b/test/Integration/test-java/src/main/java/com/function/AddProductColumnTypes.java @@ -17,6 +17,7 @@ import com.microsoft.azure.functions.sql.annotation.SQLOutput; import com.function.Common.ProductColumnTypes; +import java.math.BigDecimal; import java.sql.Timestamp; import java.util.Optional; @@ -37,8 +38,11 @@ public HttpResponseMessage run( ProductColumnTypes p = new ProductColumnTypes( Integer.parseInt(request.getQueryParameters().get("productId")), - new Timestamp(System.currentTimeMillis()), - new Timestamp(System.currentTimeMillis())); + (long)999, true, new BigDecimal("1.2345"), new BigDecimal("1.2345"), + new BigDecimal("1.2345"), (short)1, new BigDecimal("1.2345"), (short)1, 0.1, 0.1, new Timestamp(System.currentTimeMillis()), + new Timestamp(System.currentTimeMillis()), new Timestamp(System.currentTimeMillis()), + new Timestamp(System.currentTimeMillis()), new Timestamp(System.currentTimeMillis()), + new Timestamp(System.currentTimeMillis()), "test", "test", "test", "test"); product.setValue(p); // Items were inserted successfully so return success, an exception would be thrown if there diff --git a/test/Integration/test-java/src/main/java/com/function/Common/ProductColumnTypes.java b/test/Integration/test-java/src/main/java/com/function/Common/ProductColumnTypes.java index 7cfbb7a2c..887b043f1 100644 --- a/test/Integration/test-java/src/main/java/com/function/Common/ProductColumnTypes.java +++ b/test/Integration/test-java/src/main/java/com/function/Common/ProductColumnTypes.java @@ -4,27 +4,154 @@ * license information. */ -package com.function.Common; + package com.function.Common; +import java.math.BigDecimal; import java.sql.Timestamp; public class ProductColumnTypes { private int ProductId; + private long BigInt; + private boolean Bit; + private BigDecimal DecimalType; + private BigDecimal Money; + private BigDecimal Numeric; + private short SmallInt; + private BigDecimal SmallMoney; + private short TinyInt; + private double FloatType; + private double Real; + private Timestamp Date; private Timestamp Datetime; private Timestamp Datetime2; + private Timestamp DatetimeOffset; + private Timestamp SmallDatetime; + private Timestamp Time; + private String CharType; + private String Varchar; + private String Nchar; + private String Nvarchar; + // private String UniqueIdentifier; - public ProductColumnTypes(int productId, Timestamp datetime, Timestamp datetime2) { + + public ProductColumnTypes(int productId, long bigInt, boolean bit, BigDecimal decimalType, BigDecimal money, + BigDecimal numeric, short smallInt, BigDecimal smallMoney, short tinyInt, double floatType, double real, Timestamp date, + Timestamp datetime, Timestamp datetime2, Timestamp datetimeOffset, Timestamp smallDatetime, Timestamp time, String charType, + String varchar, String nchar, String nvarchar) { ProductId = productId; + BigInt = bigInt; + Bit = bit; + DecimalType = decimalType; + Money = money; + Numeric = numeric; + SmallInt = smallInt; + SmallMoney = smallMoney; + TinyInt = tinyInt; + FloatType = floatType; + Real = real; + Date = date; Datetime = datetime; Datetime2 = datetime2; + DatetimeOffset = datetimeOffset; + SmallDatetime = smallDatetime; + Time = time; + CharType = charType; + Varchar = varchar; + Nchar = nchar; + Nvarchar = nvarchar; + // UniqueIdentifier = uniqueIdentifier; } public int getProductId() { return ProductId; } - public void setProductId(int productId) { - ProductId = productId; + public long getBigint() { + return BigInt; + } + + public void setBigint(long bigInt) { + BigInt = bigInt; + } + + public boolean setBit() { + return Bit; + } + + public void setBit(boolean bit) { + Bit = bit; + } + + public BigDecimal getDecimalType() { + return DecimalType; + } + + public void setDecimalType(BigDecimal decimalType) { + DecimalType = decimalType; + } + + public BigDecimal getMoney() { + return Money; + } + + public void setMoney(BigDecimal money) { + Money = money; + } + + public BigDecimal getNumeric() { + return Numeric; + } + + public void setNumeric(BigDecimal numeric) { + Numeric = numeric; + } + + public short getSmallInt() { + return SmallInt; + } + + public void setSmallInt(short smallInt) { + SmallInt = smallInt; + } + + public BigDecimal getSmallMoney() { + return SmallMoney; + } + + public void setSmallMoney(BigDecimal smallMoney) { + SmallMoney = smallMoney; + } + + public short getTinyInt() { + return TinyInt; + } + + public void setTinyInt(short tinyInt) { + TinyInt = tinyInt; + } + + public double getFloatType() { + return FloatType; + } + + public void setFloatType(double floatType) { + FloatType = floatType; + } + + public double getReal() { + return Real; + } + + public void setReal(double real) { + Real = real; + } + + public Timestamp getDate() { + return Date; + } + + public void setDate(Timestamp date) { + Date = date; } public Timestamp getDatetime() { @@ -42,4 +169,68 @@ public Timestamp getDatetime2() { public void setDatetime2(Timestamp datetime2) { Datetime2 = datetime2; } -} + + public Timestamp getDatetimeOffset() { + return DatetimeOffset; + } + + public void setDatetimeOffset(Timestamp datetimeOffset) { + DatetimeOffset = datetimeOffset; + } + + public Timestamp getSmallDatetime() { + return SmallDatetime; + } + + public void setSmallDatetime(Timestamp smallDatetime) { + SmallDatetime = smallDatetime; + } + + public Timestamp getTime() { + return Time; + } + + public void setTime(Timestamp time) { + Time = time; + } + + public String getCharType() { + return CharType; + } + + public void setCharType(String charType) { + CharType = charType; + } + + public String getVarchar() { + return Varchar; + } + + public void setVarchar(String varchar) { + Varchar = varchar; + } + + public String getNchar() { + return Nchar; + } + + public void setNchar(String nchar) { + Nchar = nchar; + } + + public String getNvarchar() { + return Nvarchar; + } + + public void setNvarchar(String nvarchar) { + Nvarchar = nvarchar; + } + + // public String getUniqueIdentifier() { + // return UniqueIdentifier; + // } + + // public void setUniqueIdentifier(String uniqueIdentifier) { + // UniqueIdentifier = uniqueIdentifier; + // } +} \ No newline at end of file diff --git a/test/Integration/test-js/AddProductColumnTypes/index.js b/test/Integration/test-js/AddProductColumnTypes/index.js index 7e0e777b9..374073924 100644 --- a/test/Integration/test-js/AddProductColumnTypes/index.js +++ b/test/Integration/test-js/AddProductColumnTypes/index.js @@ -8,8 +8,26 @@ module.exports = async function (context, req) { const product = { "ProductId": req.query.productId, + "BigInt": 999, + "Bit": true, + "DecimalType": 1.2345, + "Money": 1.2345, + "Numeric": 1.2345, + "SmallInt": 1, + "SmallMoney": 1.2345, + "TinyInt": 1, + "FloatType": 0.1, + "Real": 0.1, + "Date": new Date().toISOString(), "Datetime": new Date().toISOString(), - "Datetime2": new Date().toISOString() + "Datetime2": new Date().toISOString(), + "DatetimeOffSet": new Date().toISOString(), + "SmallDatetime": new Date().toISOString(), + "Time": new Date().toISOString(), + "CharType": "test", + "Varchar": "test", + "Nchar": "test", + "Nvarchar": "test" }; context.bindings.product = JSON.stringify(product); diff --git a/test/Integration/test-powershell/AddProductColumnTypes/run.ps1 b/test/Integration/test-powershell/AddProductColumnTypes/run.ps1 index 7d52e5adb..bdab18c89 100644 --- a/test/Integration/test-powershell/AddProductColumnTypes/run.ps1 +++ b/test/Integration/test-powershell/AddProductColumnTypes/run.ps1 @@ -9,17 +9,35 @@ Write-Host "PowerShell function with SQL Output Binding processed a request." # Update req_body with the body of the request # Note that this expects the body to be a JSON object or array of objects # which have a property matching each of the columns in the table to upsert to. -$req_query = @{ +$req_query = @{ ProductId=$Request.QUERY.productId; + BigInt=999; + Bit=$true; + DecimalType=1.2345; + Money=1.2345; + Numeric=1.2345; + SmallInt=1; + SmallMoney=1.2345; + TinyInt=1; + FloatType=0.1; + Real=0.1; + Date=Get-Date -AsUTC; Datetime=Get-Date -AsUTC; Datetime2=Get-Date -AsUTC; + DatetimeOffSet=Get-Date -AsUTC; + SmallDatetime=Get-Date -AsUTC; + Time=Get-Date -AsUTC; + CharType="test"; + Varchar="test"; + Nchar="test"; + Nvarchar="test; }; -# Assign the value we want to pass to the SQL Output binding. +# Assign the value we want to pass to the SQL Output binding. # The -Name value corresponds to the name property in the function.json for the binding Push-OutputBinding -Name product -Value $req_query -# Assign the value to return as the HTTP response. +# Assign the value to return as the HTTP response. # The -Name value matches the name property in the function.json for the binding Push-OutputBinding -Name response -Value ([HttpResponseContext]@{ StatusCode = [HttpStatusCode]::OK diff --git a/test/Integration/test-python/AddProductColumnTypes/__init__.py b/test/Integration/test-python/AddProductColumnTypes/__init__.py index f57c74c70..500a7f863 100644 --- a/test/Integration/test-python/AddProductColumnTypes/__init__.py +++ b/test/Integration/test-python/AddProductColumnTypes/__init__.py @@ -9,7 +9,12 @@ # This function is used to test compatibility with converting various data types to their respective # SQL server types. def main(req: func.HttpRequest, product: func.Out[func.SqlRow]) -> func.HttpResponse: - productColumnTypes = func.SqlRow(ProductColumnTypes(req.params["productId"], datetime.datetime.utcnow().isoformat("T", "milliseconds"), datetime.datetime.utcnow().isoformat("T", "milliseconds"))) + productColumnTypes = func.SqlRow(ProductColumnTypes(req.params["productId"], + 999, True, 1.2345, 1.2345, 1.2345, 1, 1.2345, 1, 0.1, 0.1, + datetime.datetime.utcnow().isoformat("T", "milliseconds"), datetime.datetime.utcnow().isoformat("T", "milliseconds"), + datetime.datetime.utcnow().isoformat("T", "milliseconds"), datetime.datetime.utcnow().isoformat("T", "milliseconds"), + datetime.datetime.utcnow().isoformat("T", "milliseconds"), datetime.datetime.utcnow().isoformat("T", "milliseconds"), + "test", "test", "test", "test")) product.set(productColumnTypes) return func.HttpResponse( From 9264c527625598b1096c1857ac5d533f90e8540c Mon Sep 17 00:00:00 2001 From: Lucy Zhang Date: Fri, 13 Jan 2023 09:12:35 -0800 Subject: [PATCH 02/13] Fix TIME in Java --- .../SqlInputBindingIntegrationTests.cs | 2 -- .../com/function/AddProductColumnTypes.java | 26 +++++++++++++++---- .../function/Common/ProductColumnTypes.java | 8 +++--- .../AddProductColumnTypes/__init__.py | 26 +++++++++++++++---- 4 files changed, 46 insertions(+), 16 deletions(-) diff --git a/test/Integration/SqlInputBindingIntegrationTests.cs b/test/Integration/SqlInputBindingIntegrationTests.cs index a2c65d7f7..deec982d7 100644 --- a/test/Integration/SqlInputBindingIntegrationTests.cs +++ b/test/Integration/SqlInputBindingIntegrationTests.cs @@ -202,8 +202,6 @@ public async void GetProductsColumnTypesSerializationTest(SupportedLanguages lan ProductColumnTypes[] expectedResponse = JsonConvert.DeserializeObject("[{\"ProductId\":999,\"BigInt\":999,\"Bit\":true,\"DecimalType\":1.2345,\"Money\":1.2345,\"Numeric\":1.2345,\"SmallInt\":1,\"SmallMoney\":1.2345,\"TinyInt\":1,\"FloatType\":0.1,\"Real\":0.1,\"Date\":\"2022-10-20T00:00:00.000Z\",\"Datetime\":\"2022-10-20T12:39:13.123Z\",\"Datetime2\":\"2022-10-20T12:39:13.123Z\",\"DatetimeOffset\":\"2022-10-20T12:39:13.123Z\",\"SmallDatetime\":\"2022-10-20T12:39:00.000Z\",\"Time\":\"12:39:13.1230000\",\"CharType\":\"test\",\"Varchar\":\"test\",\"Nchar\":\"test\",\"Nvarchar\":\"test\"}]"); string actualResponse = await response.Content.ReadAsStringAsync(); ProductColumnTypes[] actualProductResponse = JsonConvert.DeserializeObject(actualResponse); - Console.WriteLine(expectedResponse[0].ToString()); - Console.WriteLine(actualProductResponse[0].ToString()); Assert.Equal(expectedResponse, actualProductResponse); } diff --git a/test/Integration/test-java/src/main/java/com/function/AddProductColumnTypes.java b/test/Integration/test-java/src/main/java/com/function/AddProductColumnTypes.java index 431cbd12a..175c13e62 100644 --- a/test/Integration/test-java/src/main/java/com/function/AddProductColumnTypes.java +++ b/test/Integration/test-java/src/main/java/com/function/AddProductColumnTypes.java @@ -19,6 +19,7 @@ import java.math.BigDecimal; import java.sql.Timestamp; +import java.sql.Time; import java.util.Optional; public class AddProductColumnTypes { @@ -38,11 +39,26 @@ public HttpResponseMessage run( ProductColumnTypes p = new ProductColumnTypes( Integer.parseInt(request.getQueryParameters().get("productId")), - (long)999, true, new BigDecimal("1.2345"), new BigDecimal("1.2345"), - new BigDecimal("1.2345"), (short)1, new BigDecimal("1.2345"), (short)1, 0.1, 0.1, new Timestamp(System.currentTimeMillis()), - new Timestamp(System.currentTimeMillis()), new Timestamp(System.currentTimeMillis()), - new Timestamp(System.currentTimeMillis()), new Timestamp(System.currentTimeMillis()), - new Timestamp(System.currentTimeMillis()), "test", "test", "test", "test"); + (long)999, + true, + new BigDecimal("1.2345"), + new BigDecimal("1.2345"), + new BigDecimal("1.2345"), + (short)1, + new BigDecimal("1.2345"), + (short)1, + 0.1, + 0.1, + new Timestamp(System.currentTimeMillis()), + new Timestamp(System.currentTimeMillis()), + new Timestamp(System.currentTimeMillis()), + new Timestamp(System.currentTimeMillis()), + new Timestamp(System.currentTimeMillis()), + new Time(System.currentTimeMillis()).toString(), + "test", + "test", + "test", + "test"); product.setValue(p); // Items were inserted successfully so return success, an exception would be thrown if there diff --git a/test/Integration/test-java/src/main/java/com/function/Common/ProductColumnTypes.java b/test/Integration/test-java/src/main/java/com/function/Common/ProductColumnTypes.java index 887b043f1..0fd4e6f59 100644 --- a/test/Integration/test-java/src/main/java/com/function/Common/ProductColumnTypes.java +++ b/test/Integration/test-java/src/main/java/com/function/Common/ProductColumnTypes.java @@ -26,7 +26,7 @@ public class ProductColumnTypes { private Timestamp Datetime2; private Timestamp DatetimeOffset; private Timestamp SmallDatetime; - private Timestamp Time; + private String Time; private String CharType; private String Varchar; private String Nchar; @@ -36,7 +36,7 @@ public class ProductColumnTypes { public ProductColumnTypes(int productId, long bigInt, boolean bit, BigDecimal decimalType, BigDecimal money, BigDecimal numeric, short smallInt, BigDecimal smallMoney, short tinyInt, double floatType, double real, Timestamp date, - Timestamp datetime, Timestamp datetime2, Timestamp datetimeOffset, Timestamp smallDatetime, Timestamp time, String charType, + Timestamp datetime, Timestamp datetime2, Timestamp datetimeOffset, Timestamp smallDatetime, String time, String charType, String varchar, String nchar, String nvarchar) { ProductId = productId; BigInt = bigInt; @@ -186,11 +186,11 @@ public void setSmallDatetime(Timestamp smallDatetime) { SmallDatetime = smallDatetime; } - public Timestamp getTime() { + public String getTime() { return Time; } - public void setTime(Timestamp time) { + public void setTime(String time) { Time = time; } diff --git a/test/Integration/test-python/AddProductColumnTypes/__init__.py b/test/Integration/test-python/AddProductColumnTypes/__init__.py index 500a7f863..d9ecfe454 100644 --- a/test/Integration/test-python/AddProductColumnTypes/__init__.py +++ b/test/Integration/test-python/AddProductColumnTypes/__init__.py @@ -10,11 +10,27 @@ # SQL server types. def main(req: func.HttpRequest, product: func.Out[func.SqlRow]) -> func.HttpResponse: productColumnTypes = func.SqlRow(ProductColumnTypes(req.params["productId"], - 999, True, 1.2345, 1.2345, 1.2345, 1, 1.2345, 1, 0.1, 0.1, - datetime.datetime.utcnow().isoformat("T", "milliseconds"), datetime.datetime.utcnow().isoformat("T", "milliseconds"), - datetime.datetime.utcnow().isoformat("T", "milliseconds"), datetime.datetime.utcnow().isoformat("T", "milliseconds"), - datetime.datetime.utcnow().isoformat("T", "milliseconds"), datetime.datetime.utcnow().isoformat("T", "milliseconds"), - "test", "test", "test", "test")) + 999, + True, + 1.2345, + 1.2345, + 1.2345, + 1, + 1.2345, + 1, + 0.1, + 0.1, + datetime.datetime.utcnow().isoformat("T", "milliseconds"), + datetime.datetime.utcnow().isoformat("T", "milliseconds"), + datetime.datetime.utcnow().isoformat("T", "milliseconds"), + datetime.datetime.utcnow().isoformat("T", "milliseconds"), + datetime.datetime.utcnow().isoformat("T", "milliseconds"), + datetime.datetime.utcnow().isoformat("T", "milliseconds"), + "test", + "test", + "test", + "test") + ) product.set(productColumnTypes) return func.HttpResponse( From 9b218bb48e39ebcd62b1940febdd022bf8ed7e64 Mon Sep 17 00:00:00 2001 From: Lucy Zhang Date: Fri, 13 Jan 2023 13:08:57 -0800 Subject: [PATCH 03/13] fix java test --- test-outofproc/Product.cs | 1 + test/Integration/SqlInputBindingIntegrationTests.cs | 4 ++-- .../com/function/GetProductsColumnTypesSerialization.java | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/test-outofproc/Product.cs b/test-outofproc/Product.cs index 868d43352..301f5ec6e 100644 --- a/test-outofproc/Product.cs +++ b/test-outofproc/Product.cs @@ -153,6 +153,7 @@ public override bool Equals(object obj) } return false; } + } public class ProductExtraColumns { diff --git a/test/Integration/SqlInputBindingIntegrationTests.cs b/test/Integration/SqlInputBindingIntegrationTests.cs index deec982d7..99b3dda65 100644 --- a/test/Integration/SqlInputBindingIntegrationTests.cs +++ b/test/Integration/SqlInputBindingIntegrationTests.cs @@ -177,7 +177,7 @@ public async void GetProductsColumnTypesSerializationTest(SupportedLanguages lan this.ExecuteNonQuery("INSERT INTO [dbo].[ProductsColumnTypes] VALUES (" + "999, " + // ProductId, "999, " + // BigInt - "1, " + // Bit + "0, " + // Bit "1.2345, " + // DecimalType "1.2345, " + // Money "1.2345, " + // Numeric @@ -199,7 +199,7 @@ public async void GetProductsColumnTypesSerializationTest(SupportedLanguages lan HttpResponseMessage response = await this.SendInputRequest("getproducts-columntypesserialization"); // We expect the date fields to be returned in UTC format - ProductColumnTypes[] expectedResponse = JsonConvert.DeserializeObject("[{\"ProductId\":999,\"BigInt\":999,\"Bit\":true,\"DecimalType\":1.2345,\"Money\":1.2345,\"Numeric\":1.2345,\"SmallInt\":1,\"SmallMoney\":1.2345,\"TinyInt\":1,\"FloatType\":0.1,\"Real\":0.1,\"Date\":\"2022-10-20T00:00:00.000Z\",\"Datetime\":\"2022-10-20T12:39:13.123Z\",\"Datetime2\":\"2022-10-20T12:39:13.123Z\",\"DatetimeOffset\":\"2022-10-20T12:39:13.123Z\",\"SmallDatetime\":\"2022-10-20T12:39:00.000Z\",\"Time\":\"12:39:13.1230000\",\"CharType\":\"test\",\"Varchar\":\"test\",\"Nchar\":\"test\",\"Nvarchar\":\"test\"}]"); + ProductColumnTypes[] expectedResponse = JsonConvert.DeserializeObject("[{\"ProductId\":999,\"BigInt\":999,\"Bit\":false,\"DecimalType\":1.2345,\"Money\":1.2345,\"Numeric\":1.2345,\"SmallInt\":1,\"SmallMoney\":1.2345,\"TinyInt\":1,\"FloatType\":0.1,\"Real\":0.1,\"Date\":\"2022-10-20T00:00:00.000Z\",\"Datetime\":\"2022-10-20T12:39:13.123Z\",\"Datetime2\":\"2022-10-20T12:39:13.123Z\",\"DatetimeOffset\":\"2022-10-20T12:39:13.123Z\",\"SmallDatetime\":\"2022-10-20T12:39:00.000Z\",\"Time\":\"12:39:13.1230000\",\"CharType\":\"test\",\"Varchar\":\"test\",\"Nchar\":\"test\",\"Nvarchar\":\"test\"}]"); string actualResponse = await response.Content.ReadAsStringAsync(); ProductColumnTypes[] actualProductResponse = JsonConvert.DeserializeObject(actualResponse); diff --git a/test/Integration/test-java/src/main/java/com/function/GetProductsColumnTypesSerialization.java b/test/Integration/test-java/src/main/java/com/function/GetProductsColumnTypesSerialization.java index 0ec538b96..0fae41c0e 100644 --- a/test/Integration/test-java/src/main/java/com/function/GetProductsColumnTypesSerialization.java +++ b/test/Integration/test-java/src/main/java/com/function/GetProductsColumnTypesSerialization.java @@ -47,11 +47,15 @@ public HttpResponseMessage run( mapper.setDateFormat(df); for (ProductColumnTypes product : products) { // Convert the datetimes to UTC (Java worker returns the datetimes in local timezone) + long date = product.getDate().getTime(); long datetime = product.getDatetime().getTime(); long datetime2 = product.getDatetime2().getTime(); + long smallDateTime = product.getSmallDatetime().getTime(); int offset = Calendar.getInstance().getTimeZone().getOffset(product.getDatetime().getTime()); + product.setDate(new Timestamp(date - offset)); product.setDatetime(new Timestamp(datetime - offset)); product.setDatetime2(new Timestamp(datetime2 - offset)); + product.setSmallDatetime(new Timestamp(smallDateTime - offset)); context.getLogger().log(Level.INFO, mapper.writeValueAsString(product)); } return request.createResponseBuilder(HttpStatus.OK).header("Content-Type", "application/json").body(mapper.writeValueAsString(products)).build(); From 0d0b7ba7b2ca9188caa2e1b14a28a3b09fddf30b Mon Sep 17 00:00:00 2001 From: Lucy Zhang Date: Tue, 17 Jan 2023 08:47:53 -0800 Subject: [PATCH 04/13] GetProductsColumnTypesSerializationAsyncEnumerable --- .../SqlInputBindingIntegrationTests.cs | 35 ++++++++++++------- .../test-js/AddProductColumnTypes/index.js | 2 +- .../AddProductColumnTypes/run.ps1 | 2 +- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/test/Integration/SqlInputBindingIntegrationTests.cs b/test/Integration/SqlInputBindingIntegrationTests.cs index 99b3dda65..24e2d2678 100644 --- a/test/Integration/SqlInputBindingIntegrationTests.cs +++ b/test/Integration/SqlInputBindingIntegrationTests.cs @@ -143,19 +143,30 @@ public async void GetProductsColumnTypesSerializationAsyncEnumerableTest(string this.StartFunctionHost(nameof(GetProductsColumnTypesSerializationAsyncEnumerable), lang, true); string datetime = "2022-10-20 12:39:13.123"; - ProductColumnTypes[] expectedResponse = new[] - { - new ProductColumnTypes() - { - ProductId = 999, - Datetime = DateTime.Parse(datetime), - Datetime2 = DateTime.Parse(datetime) - } - }; + ProductColumnTypes[] expectedResponse = JsonConvert.DeserializeObject("[{\"ProductId\":999,\"BigInt\":999,\"Bit\":false,\"DecimalType\":1.2345,\"Money\":1.2345,\"Numeric\":1.2345,\"SmallInt\":1,\"SmallMoney\":1.2345,\"TinyInt\":1,\"FloatType\":0.1,\"Real\":0.1,\"Date\":\"2022-10-20T00:00:00.000Z\",\"Datetime\":\"2022-10-20T12:39:13.123Z\",\"Datetime2\":\"2022-10-20T12:39:13.123Z\",\"DatetimeOffset\":\"2022-10-20T12:39:13.123Z\",\"SmallDatetime\":\"2022-10-20T12:39:00.000Z\",\"Time\":\"12:39:13.1230000\",\"CharType\":\"test\",\"Varchar\":\"test\",\"Nchar\":\"test\",\"Nvarchar\":\"test\"}]"); + this.ExecuteNonQuery("INSERT INTO [dbo].[ProductsColumnTypes] VALUES (" + - "999, " + // ProductId - $"CONVERT(DATETIME, '{datetime}'), " + // Datetime field - $"CONVERT(DATETIME2, '{datetime}'))"); // Datetime2 field + "999, " + // ProductId, + "999, " + // BigInt + "0, " + // Bit + "1.2345, " + // DecimalType + "1.2345, " + // Money + "1.2345, " + // Numeric + "1, " + // SmallInt + "1.2345, " + // SmallMoney + "1, " + // TinyInt + ".1, " + // FloatType + ".1, " + // Real + $"CONVERT(DATE, '{datetime}'), " + // Date + $"CONVERT(DATETIME, '{datetime}'), " + // Datetime + $"CONVERT(DATETIME2, '{datetime}'), " + // Datetime2 + $"CONVERT(DATETIMEOFFSET, '{datetime}'), " + // DatetimeOffSet + $"CONVERT(SMALLDATETIME, '{datetime}'), " + // SmallDatetime + $"CONVERT(TIME, '{datetime}'), " + // Time + "'test', " + // CharType + "'test', " + // Varchar + "'test', " + // Nchar + "'test')"); // Nvarchar HttpResponseMessage response = await this.SendInputRequest("getproducts-columntypesserializationasyncenumerable", $"?culture={culture}"); // We expect the datetime and datetime2 fields to be returned in UTC format diff --git a/test/Integration/test-js/AddProductColumnTypes/index.js b/test/Integration/test-js/AddProductColumnTypes/index.js index 374073924..0e6aa15c2 100644 --- a/test/Integration/test-js/AddProductColumnTypes/index.js +++ b/test/Integration/test-js/AddProductColumnTypes/index.js @@ -21,7 +21,7 @@ module.exports = async function (context, req) { "Date": new Date().toISOString(), "Datetime": new Date().toISOString(), "Datetime2": new Date().toISOString(), - "DatetimeOffSet": new Date().toISOString(), + "DatetimeOffset": new Date().toISOString(), "SmallDatetime": new Date().toISOString(), "Time": new Date().toISOString(), "CharType": "test", diff --git a/test/Integration/test-powershell/AddProductColumnTypes/run.ps1 b/test/Integration/test-powershell/AddProductColumnTypes/run.ps1 index bdab18c89..2908a39d9 100644 --- a/test/Integration/test-powershell/AddProductColumnTypes/run.ps1 +++ b/test/Integration/test-powershell/AddProductColumnTypes/run.ps1 @@ -7,7 +7,7 @@ param($Request, $TriggerMetadata) Write-Host "PowerShell function with SQL Output Binding processed a request." # Update req_body with the body of the request -# Note that this expects the body to be a JSON object or array of objects +# Note that this expects the body to be a JSON object or array of objects # which have a property matching each of the columns in the table to upsert to. $req_query = @{ ProductId=$Request.QUERY.productId; From a02a807717fd38a631e69e5390236302e8f9f3cd Mon Sep 17 00:00:00 2001 From: Lucy Zhang Date: Tue, 17 Jan 2023 12:25:11 -0800 Subject: [PATCH 05/13] add product column types test --- .../Common/productcolumntypes.py | 22 +++++++++++++++++- test-outofproc/AddProductColumnTypes.cs | 20 +++++++++++++++- test/Database/Tables/ProductsColumnTypes.sql | 2 -- .../SqlOutputBindingIntegrationTests.cs | 1 - .../test-csharp/AddProductColumnTypes.cs | 2 -- .../AddProductColumnTypes/run.ps1 | 14 +++++------ .../test-python/Common/productcolumntypes.py | 23 ++++++++++++++++++- 7 files changed, 69 insertions(+), 15 deletions(-) diff --git a/samples/samples-python/Common/productcolumntypes.py b/samples/samples-python/Common/productcolumntypes.py index 4cebd0962..4fa5c0a3c 100644 --- a/samples/samples-python/Common/productcolumntypes.py +++ b/samples/samples-python/Common/productcolumntypes.py @@ -4,8 +4,28 @@ import collections class ProductColumnTypes(collections.UserDict): - def __init__(self, productId, datetime, datetime2): + def __init__(self, productId, bigInt, bit, decimalType, money, numeric, smallInt, + smallMoney, tinyInt, floatType, real, date, datetime, datetime2, datetimeOffset, + smallDatetime, time, charType, varchar, nchar, nvarchar): super().__init__() self['ProductId'] = productId + self['BigInt'] = bigInt + self['Bit'] = bit + self['DecimalType'] = decimalType + self['Money'] = money + self['Numeric'] = numeric + self['SmallInt'] = smallInt + self['SmallMoney'] = smallMoney + self['TinyInt'] = tinyInt + self['FloatType'] = floatType + self['Real'] = real + self['Date'] = date self['Datetime'] = datetime self['Datetime2'] = datetime2 + self['DatetimeOffset'] = datetimeOffset + self['SmallDatetime'] = smallDatetime + self['Time'] = time + self['CharType'] = charType + self['Varchar'] = varchar + self['Nchar'] = nchar + self['Nvarchar'] = nvarchar diff --git a/test-outofproc/AddProductColumnTypes.cs b/test-outofproc/AddProductColumnTypes.cs index 8d26228b7..51f3ed383 100644 --- a/test-outofproc/AddProductColumnTypes.cs +++ b/test-outofproc/AddProductColumnTypes.cs @@ -27,8 +27,26 @@ public static ProductColumnTypes Run( var product = new ProductColumnTypes() { ProductId = int.Parse(queryStrings["productId"], null), + BigInt = int.MaxValue, + Bit = true, + DecimalType = 1.2345M, + Money = 1.23M, + Numeric = 1.2345M, + SmallInt = 0, + SmallMoney = 1.23M, + TinyInt = 1, + FloatType = 1.2, + Real = 1.2f, + Date = DateTime.UtcNow, Datetime = new SqlDateTime(DateTime.UtcNow).Value, - Datetime2 = DateTime.UtcNow + Datetime2 = DateTime.UtcNow, + DatetimeOffset = DateTime.UtcNow, + SmallDatetime = new SqlDateTime(DateTime.UtcNow).Value, + Time = DateTime.UtcNow.TimeOfDay, + CharType = "test", + Varchar = "test", + Nchar = "test", + Nvarchar = "test", }; return product; } diff --git a/test/Database/Tables/ProductsColumnTypes.sql b/test/Database/Tables/ProductsColumnTypes.sql index 568ad7f02..6ec8950b5 100644 --- a/test/Database/Tables/ProductsColumnTypes.sql +++ b/test/Database/Tables/ProductsColumnTypes.sql @@ -20,6 +20,4 @@ [Varchar] [varchar](100), [Nchar] [nchar](4), [Nvarchar] [nvarchar](100), - -- [Binary] [binary], - -- [Varbinary] [varbinary] ) diff --git a/test/Integration/SqlOutputBindingIntegrationTests.cs b/test/Integration/SqlOutputBindingIntegrationTests.cs index 055c1912e..43a63979c 100644 --- a/test/Integration/SqlOutputBindingIntegrationTests.cs +++ b/test/Integration/SqlOutputBindingIntegrationTests.cs @@ -110,7 +110,6 @@ public void AddProductArrayTest(SupportedLanguages lang) /// The language to run the test against [Theory] [SqlInlineData()] - [UnsupportedLanguages(SupportedLanguages.Java, SupportedLanguages.PowerShell)] public void AddProductColumnTypesTest(SupportedLanguages lang) { this.StartFunctionHost(nameof(AddProductColumnTypes), lang, true); diff --git a/test/Integration/test-csharp/AddProductColumnTypes.cs b/test/Integration/test-csharp/AddProductColumnTypes.cs index 7eb53bf76..8153f4b68 100644 --- a/test/Integration/test-csharp/AddProductColumnTypes.cs +++ b/test/Integration/test-csharp/AddProductColumnTypes.cs @@ -43,8 +43,6 @@ public static IActionResult Run( Varchar = "test", Nchar = "test", Nvarchar = "test", - // Binary = new byte[] { 1, 2, 3 }, - // Varbinary = new byte[] { 1, 2, 3 } }; // Items were inserted successfully so return success, an exception would be thrown if there diff --git a/test/Integration/test-powershell/AddProductColumnTypes/run.ps1 b/test/Integration/test-powershell/AddProductColumnTypes/run.ps1 index 2908a39d9..9a243905f 100644 --- a/test/Integration/test-powershell/AddProductColumnTypes/run.ps1 +++ b/test/Integration/test-powershell/AddProductColumnTypes/run.ps1 @@ -21,16 +21,16 @@ $req_query = @{ TinyInt=1; FloatType=0.1; Real=0.1; - Date=Get-Date -AsUTC; - Datetime=Get-Date -AsUTC; - Datetime2=Get-Date -AsUTC; - DatetimeOffSet=Get-Date -AsUTC; - SmallDatetime=Get-Date -AsUTC; - Time=Get-Date -AsUTC; + Date=Get-Date -AsUTC -Format "yyyy-MM-dd"; + Datetime=Get-Date -AsUTC -Format "yyyy-MM-ddTHH:mm:ss"; + Datetime2=Get-Date -AsUTC -Format "yyyy-MM-ddTHH:mm:ss"; + DatetimeOffset=Get-Date -AsUTC -Format "yyyy-MM-ddTHH:mm:sszzz"; + SmallDatetime=Get-Date -AsUTC -Format "yyyy-MM-ddTHH:mm:ss"; + Time=Get-Date -AsUTC -Format "HH:mm:ss"; CharType="test"; Varchar="test"; Nchar="test"; - Nvarchar="test; + Nvarchar="test"; }; # Assign the value we want to pass to the SQL Output binding. diff --git a/test/Integration/test-python/Common/productcolumntypes.py b/test/Integration/test-python/Common/productcolumntypes.py index 4cebd0962..f24a08dda 100644 --- a/test/Integration/test-python/Common/productcolumntypes.py +++ b/test/Integration/test-python/Common/productcolumntypes.py @@ -4,8 +4,29 @@ import collections class ProductColumnTypes(collections.UserDict): - def __init__(self, productId, datetime, datetime2): + def __init__(self, productId, bigInt, bit, decimalType, money, numeric, smallInt, + smallMoney, tinyInt, floatType, real, date, datetime, datetime2, datetimeOffset, + smallDatetime, time, charType, varchar, nchar, nvarchar): super().__init__() self['ProductId'] = productId + self['BigInt'] = bigInt + self['Bit'] = bit + self['DecimalType'] = decimalType + self['Money'] = money + self['Numeric'] = numeric + self['SmallInt'] = smallInt + self['SmallMoney'] = smallMoney + self['TinyInt'] = tinyInt + self['FloatType'] = floatType + self['Real'] = real + self['Date'] = date self['Datetime'] = datetime self['Datetime2'] = datetime2 + self['DatetimeOffset'] = datetimeOffset + self['SmallDatetime'] = smallDatetime + self['Time'] = time + self['CharType'] = charType + self['Varchar'] = varchar + self['Nchar'] = nchar + self['Nvarchar'] = nvarchar + From b1801cb9ca87b689a230b72d9f802b7b74ae83da Mon Sep 17 00:00:00 2001 From: Lucy Zhang Date: Tue, 17 Jan 2023 12:51:53 -0800 Subject: [PATCH 06/13] fix linting --- samples/samples-python/.pylintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/samples-python/.pylintrc b/samples/samples-python/.pylintrc index cfba7c8bd..439fba0a1 100644 --- a/samples/samples-python/.pylintrc +++ b/samples/samples-python/.pylintrc @@ -13,4 +13,4 @@ file-header=# Copyright \(c\) Microsoft Corporation\. All rights reserved\.[\r\n # can either give multiple identifier separated by comma (,) or put this option # multiple time (only on the command line, not in the configuration file where # it should appear only once). -disable= R0801, W0108, W0613, C0103, C0114, C0115, C0116, E0401, C0301 \ No newline at end of file +disable= R0801, W0108, W0613, C0103, C0114, C0115, C0116, E0401, C0301, R0913, R0914 \ No newline at end of file From 73982493a49db457b4f8afe2ef697642b123baa5 Mon Sep 17 00:00:00 2001 From: Lucy Zhang Date: Tue, 17 Jan 2023 13:03:33 -0800 Subject: [PATCH 07/13] remove productcolumntypes in samples-python --- .../Common/productcolumntypes.py | 31 ------------------- 1 file changed, 31 deletions(-) delete mode 100644 samples/samples-python/Common/productcolumntypes.py diff --git a/samples/samples-python/Common/productcolumntypes.py b/samples/samples-python/Common/productcolumntypes.py deleted file mode 100644 index 4fa5c0a3c..000000000 --- a/samples/samples-python/Common/productcolumntypes.py +++ /dev/null @@ -1,31 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -import collections - -class ProductColumnTypes(collections.UserDict): - def __init__(self, productId, bigInt, bit, decimalType, money, numeric, smallInt, - smallMoney, tinyInt, floatType, real, date, datetime, datetime2, datetimeOffset, - smallDatetime, time, charType, varchar, nchar, nvarchar): - super().__init__() - self['ProductId'] = productId - self['BigInt'] = bigInt - self['Bit'] = bit - self['DecimalType'] = decimalType - self['Money'] = money - self['Numeric'] = numeric - self['SmallInt'] = smallInt - self['SmallMoney'] = smallMoney - self['TinyInt'] = tinyInt - self['FloatType'] = floatType - self['Real'] = real - self['Date'] = date - self['Datetime'] = datetime - self['Datetime2'] = datetime2 - self['DatetimeOffset'] = datetimeOffset - self['SmallDatetime'] = smallDatetime - self['Time'] = time - self['CharType'] = charType - self['Varchar'] = varchar - self['Nchar'] = nchar - self['Nvarchar'] = nvarchar From 2e2ab0b438c2232bd83a43a7de44fb74f61fb1cc Mon Sep 17 00:00:00 2001 From: Lucy Zhang Date: Tue, 17 Jan 2023 13:07:04 -0800 Subject: [PATCH 08/13] cleanup --- test/Integration/SqlInputBindingIntegrationTests.cs | 4 ++-- .../java/com/function/Common/ProductColumnTypes.java | 9 --------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/test/Integration/SqlInputBindingIntegrationTests.cs b/test/Integration/SqlInputBindingIntegrationTests.cs index 24e2d2678..5ae3f1a80 100644 --- a/test/Integration/SqlInputBindingIntegrationTests.cs +++ b/test/Integration/SqlInputBindingIntegrationTests.cs @@ -160,7 +160,7 @@ public async void GetProductsColumnTypesSerializationAsyncEnumerableTest(string $"CONVERT(DATE, '{datetime}'), " + // Date $"CONVERT(DATETIME, '{datetime}'), " + // Datetime $"CONVERT(DATETIME2, '{datetime}'), " + // Datetime2 - $"CONVERT(DATETIMEOFFSET, '{datetime}'), " + // DatetimeOffSet + $"CONVERT(DATETIMEOFFSET, '{datetime}'), " + // DatetimeOffset $"CONVERT(SMALLDATETIME, '{datetime}'), " + // SmallDatetime $"CONVERT(TIME, '{datetime}'), " + // Time "'test', " + // CharType @@ -200,7 +200,7 @@ public async void GetProductsColumnTypesSerializationTest(SupportedLanguages lan $"CONVERT(DATE, '{datetime}'), " + // Date $"CONVERT(DATETIME, '{datetime}'), " + // Datetime $"CONVERT(DATETIME2, '{datetime}'), " + // Datetime2 - $"CONVERT(DATETIMEOFFSET, '{datetime}'), " + // DatetimeOffSet + $"CONVERT(DATETIMEOFFSET, '{datetime}'), " + // DatetimeOffset $"CONVERT(SMALLDATETIME, '{datetime}'), " + // SmallDatetime $"CONVERT(TIME, '{datetime}'), " + // Time "'test', " + // CharType diff --git a/test/Integration/test-java/src/main/java/com/function/Common/ProductColumnTypes.java b/test/Integration/test-java/src/main/java/com/function/Common/ProductColumnTypes.java index 0fd4e6f59..b9f6737be 100644 --- a/test/Integration/test-java/src/main/java/com/function/Common/ProductColumnTypes.java +++ b/test/Integration/test-java/src/main/java/com/function/Common/ProductColumnTypes.java @@ -59,7 +59,6 @@ public ProductColumnTypes(int productId, long bigInt, boolean bit, BigDecimal de Varchar = varchar; Nchar = nchar; Nvarchar = nvarchar; - // UniqueIdentifier = uniqueIdentifier; } public int getProductId() { @@ -225,12 +224,4 @@ public String getNvarchar() { public void setNvarchar(String nvarchar) { Nvarchar = nvarchar; } - - // public String getUniqueIdentifier() { - // return UniqueIdentifier; - // } - - // public void setUniqueIdentifier(String uniqueIdentifier) { - // UniqueIdentifier = uniqueIdentifier; - // } } \ No newline at end of file From b75e4747074ef91ed2f6d023f9e682c7ff139d07 Mon Sep 17 00:00:00 2001 From: Lucy Zhang Date: Tue, 17 Jan 2023 13:16:07 -0800 Subject: [PATCH 09/13] cleanup --- .../src/main/java/com/function/Common/ProductColumnTypes.java | 1 - 1 file changed, 1 deletion(-) diff --git a/test/Integration/test-java/src/main/java/com/function/Common/ProductColumnTypes.java b/test/Integration/test-java/src/main/java/com/function/Common/ProductColumnTypes.java index b9f6737be..2e16b6bb1 100644 --- a/test/Integration/test-java/src/main/java/com/function/Common/ProductColumnTypes.java +++ b/test/Integration/test-java/src/main/java/com/function/Common/ProductColumnTypes.java @@ -31,7 +31,6 @@ public class ProductColumnTypes { private String Varchar; private String Nchar; private String Nvarchar; - // private String UniqueIdentifier; public ProductColumnTypes(int productId, long bigInt, boolean bit, BigDecimal decimalType, BigDecimal money, From a194748915469f90cf1b718f5057b6bdd5e6e3e1 Mon Sep 17 00:00:00 2001 From: Lucy Zhang Date: Thu, 19 Jan 2023 10:54:38 -0800 Subject: [PATCH 10/13] add unicode --- test-outofproc/AddProductColumnTypes.cs | 4 ++-- test/Integration/SqlInputBindingIntegrationTests.cs | 12 ++++++------ .../Integration/test-csharp/AddProductColumnTypes.cs | 4 ++-- .../test-js/AddProductColumnTypes/index.js | 4 ++-- .../test-powershell/AddProductColumnTypes/run.ps1 | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/test-outofproc/AddProductColumnTypes.cs b/test-outofproc/AddProductColumnTypes.cs index 51f3ed383..2355c13c9 100644 --- a/test-outofproc/AddProductColumnTypes.cs +++ b/test-outofproc/AddProductColumnTypes.cs @@ -45,8 +45,8 @@ public static ProductColumnTypes Run( Time = DateTime.UtcNow.TimeOfDay, CharType = "test", Varchar = "test", - Nchar = "test", - Nvarchar = "test", + Nchar = "\u2649", + Nvarchar = "\u2649", }; return product; } diff --git a/test/Integration/SqlInputBindingIntegrationTests.cs b/test/Integration/SqlInputBindingIntegrationTests.cs index 5ae3f1a80..9177b9842 100644 --- a/test/Integration/SqlInputBindingIntegrationTests.cs +++ b/test/Integration/SqlInputBindingIntegrationTests.cs @@ -143,7 +143,7 @@ public async void GetProductsColumnTypesSerializationAsyncEnumerableTest(string this.StartFunctionHost(nameof(GetProductsColumnTypesSerializationAsyncEnumerable), lang, true); string datetime = "2022-10-20 12:39:13.123"; - ProductColumnTypes[] expectedResponse = JsonConvert.DeserializeObject("[{\"ProductId\":999,\"BigInt\":999,\"Bit\":false,\"DecimalType\":1.2345,\"Money\":1.2345,\"Numeric\":1.2345,\"SmallInt\":1,\"SmallMoney\":1.2345,\"TinyInt\":1,\"FloatType\":0.1,\"Real\":0.1,\"Date\":\"2022-10-20T00:00:00.000Z\",\"Datetime\":\"2022-10-20T12:39:13.123Z\",\"Datetime2\":\"2022-10-20T12:39:13.123Z\",\"DatetimeOffset\":\"2022-10-20T12:39:13.123Z\",\"SmallDatetime\":\"2022-10-20T12:39:00.000Z\",\"Time\":\"12:39:13.1230000\",\"CharType\":\"test\",\"Varchar\":\"test\",\"Nchar\":\"test\",\"Nvarchar\":\"test\"}]"); + ProductColumnTypes[] expectedResponse = JsonConvert.DeserializeObject("[{\"ProductId\":999,\"BigInt\":999,\"Bit\":false,\"DecimalType\":1.2345,\"Money\":1.2345,\"Numeric\":1.2345,\"SmallInt\":1,\"SmallMoney\":1.2345,\"TinyInt\":1,\"FloatType\":0.1,\"Real\":0.1,\"Date\":\"2022-10-20T00:00:00.000Z\",\"Datetime\":\"2022-10-20T12:39:13.123Z\",\"Datetime2\":\"2022-10-20T12:39:13.123Z\",\"DatetimeOffset\":\"2022-10-20T12:39:13.123Z\",\"SmallDatetime\":\"2022-10-20T12:39:00.000Z\",\"Time\":\"12:39:13.1230000\",\"CharType\":\"test\",\"Varchar\":\"test\",\"Nchar\":\"\uFFFD\u0020\u0020\u0020\",\"Nvarchar\":\"\uFFFD\"}]"); this.ExecuteNonQuery("INSERT INTO [dbo].[ProductsColumnTypes] VALUES (" + "999, " + // ProductId, @@ -165,8 +165,8 @@ public async void GetProductsColumnTypesSerializationAsyncEnumerableTest(string $"CONVERT(TIME, '{datetime}'), " + // Time "'test', " + // CharType "'test', " + // Varchar - "'test', " + // Nchar - "'test')"); // Nvarchar + "NCHAR(0xD84C), " + // Nchar + "NCHAR(0xD84C))"); // Nvarchar HttpResponseMessage response = await this.SendInputRequest("getproducts-columntypesserializationasyncenumerable", $"?culture={culture}"); // We expect the datetime and datetime2 fields to be returned in UTC format @@ -205,12 +205,12 @@ public async void GetProductsColumnTypesSerializationTest(SupportedLanguages lan $"CONVERT(TIME, '{datetime}'), " + // Time "'test', " + // CharType "'test', " + // Varchar - "'test', " + // Nchar - "'test')"); // Nvarchar + "NCHAR(0xD84C), " + // Nchar + "NCHAR(0xD84C))"); // Nvarchar HttpResponseMessage response = await this.SendInputRequest("getproducts-columntypesserialization"); // We expect the date fields to be returned in UTC format - ProductColumnTypes[] expectedResponse = JsonConvert.DeserializeObject("[{\"ProductId\":999,\"BigInt\":999,\"Bit\":false,\"DecimalType\":1.2345,\"Money\":1.2345,\"Numeric\":1.2345,\"SmallInt\":1,\"SmallMoney\":1.2345,\"TinyInt\":1,\"FloatType\":0.1,\"Real\":0.1,\"Date\":\"2022-10-20T00:00:00.000Z\",\"Datetime\":\"2022-10-20T12:39:13.123Z\",\"Datetime2\":\"2022-10-20T12:39:13.123Z\",\"DatetimeOffset\":\"2022-10-20T12:39:13.123Z\",\"SmallDatetime\":\"2022-10-20T12:39:00.000Z\",\"Time\":\"12:39:13.1230000\",\"CharType\":\"test\",\"Varchar\":\"test\",\"Nchar\":\"test\",\"Nvarchar\":\"test\"}]"); + ProductColumnTypes[] expectedResponse = JsonConvert.DeserializeObject("[{\"ProductId\":999,\"BigInt\":999,\"Bit\":false,\"DecimalType\":1.2345,\"Money\":1.2345,\"Numeric\":1.2345,\"SmallInt\":1,\"SmallMoney\":1.2345,\"TinyInt\":1,\"FloatType\":0.1,\"Real\":0.1,\"Date\":\"2022-10-20T00:00:00.000Z\",\"Datetime\":\"2022-10-20T12:39:13.123Z\",\"Datetime2\":\"2022-10-20T12:39:13.123Z\",\"DatetimeOffset\":\"2022-10-20T12:39:13.123Z\",\"SmallDatetime\":\"2022-10-20T12:39:00.000Z\",\"Time\":\"12:39:13.1230000\",\"CharType\":\"test\",\"Varchar\":\"test\",\"Nchar\":\"\uFFFD\u0020\u0020\u0020\",\"Nvarchar\":\"\uFFFD\"}]"); string actualResponse = await response.Content.ReadAsStringAsync(); ProductColumnTypes[] actualProductResponse = JsonConvert.DeserializeObject(actualResponse); diff --git a/test/Integration/test-csharp/AddProductColumnTypes.cs b/test/Integration/test-csharp/AddProductColumnTypes.cs index 8153f4b68..cb2f61c77 100644 --- a/test/Integration/test-csharp/AddProductColumnTypes.cs +++ b/test/Integration/test-csharp/AddProductColumnTypes.cs @@ -41,8 +41,8 @@ public static IActionResult Run( Time = DateTime.Now.TimeOfDay, CharType = "test", Varchar = "test", - Nchar = "test", - Nvarchar = "test", + Nchar = "\u2649", + Nvarchar = "\u2649", }; // Items were inserted successfully so return success, an exception would be thrown if there diff --git a/test/Integration/test-js/AddProductColumnTypes/index.js b/test/Integration/test-js/AddProductColumnTypes/index.js index 0e6aa15c2..6b15e3df3 100644 --- a/test/Integration/test-js/AddProductColumnTypes/index.js +++ b/test/Integration/test-js/AddProductColumnTypes/index.js @@ -26,8 +26,8 @@ module.exports = async function (context, req) { "Time": new Date().toISOString(), "CharType": "test", "Varchar": "test", - "Nchar": "test", - "Nvarchar": "test" + "Nchar": "\u2649", + "Nvarchar": "\u2649" }; context.bindings.product = JSON.stringify(product); diff --git a/test/Integration/test-powershell/AddProductColumnTypes/run.ps1 b/test/Integration/test-powershell/AddProductColumnTypes/run.ps1 index 9a243905f..785a2edce 100644 --- a/test/Integration/test-powershell/AddProductColumnTypes/run.ps1 +++ b/test/Integration/test-powershell/AddProductColumnTypes/run.ps1 @@ -29,8 +29,8 @@ $req_query = @{ Time=Get-Date -AsUTC -Format "HH:mm:ss"; CharType="test"; Varchar="test"; - Nchar="test"; - Nvarchar="test"; + Nchar="\u2649"; + Nvarchar="\u2649"; }; # Assign the value we want to pass to the SQL Output binding. From 2325726f5188c5a1e4d79f8dd358c2a7903c5a0a Mon Sep 17 00:00:00 2001 From: Lucy Zhang Date: Thu, 19 Jan 2023 12:42:46 -0800 Subject: [PATCH 11/13] skip java addproductcolumntypestest --- test/Integration/SqlOutputBindingIntegrationTests.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/Integration/SqlOutputBindingIntegrationTests.cs b/test/Integration/SqlOutputBindingIntegrationTests.cs index 43a63979c..bc488f2be 100644 --- a/test/Integration/SqlOutputBindingIntegrationTests.cs +++ b/test/Integration/SqlOutputBindingIntegrationTests.cs @@ -110,6 +110,8 @@ public void AddProductArrayTest(SupportedLanguages lang) /// The language to run the test against [Theory] [SqlInlineData()] + // Tracking issue here: https://github.com/Azure/azure-functions-sql-extension/issues/521 + [UnsupportedLanguages(SupportedLanguages.Java)] public void AddProductColumnTypesTest(SupportedLanguages lang) { this.StartFunctionHost(nameof(AddProductColumnTypes), lang, true); From 7fb3fe677c721f16227c2b480c6c58fd25c2c233 Mon Sep 17 00:00:00 2001 From: Lucy Zhang Date: Thu, 19 Jan 2023 13:31:42 -0800 Subject: [PATCH 12/13] add unicode to java and python test --- .../src/main/java/com/function/AddProductColumnTypes.java | 4 ++-- .../Integration/test-python/AddProductColumnTypes/__init__.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/Integration/test-java/src/main/java/com/function/AddProductColumnTypes.java b/test/Integration/test-java/src/main/java/com/function/AddProductColumnTypes.java index 175c13e62..b2e880d7c 100644 --- a/test/Integration/test-java/src/main/java/com/function/AddProductColumnTypes.java +++ b/test/Integration/test-java/src/main/java/com/function/AddProductColumnTypes.java @@ -57,8 +57,8 @@ public HttpResponseMessage run( new Time(System.currentTimeMillis()).toString(), "test", "test", - "test", - "test"); + "\u2649", + "\u2649"); product.setValue(p); // Items were inserted successfully so return success, an exception would be thrown if there diff --git a/test/Integration/test-python/AddProductColumnTypes/__init__.py b/test/Integration/test-python/AddProductColumnTypes/__init__.py index d9ecfe454..727eecbf9 100644 --- a/test/Integration/test-python/AddProductColumnTypes/__init__.py +++ b/test/Integration/test-python/AddProductColumnTypes/__init__.py @@ -28,8 +28,8 @@ def main(req: func.HttpRequest, product: func.Out[func.SqlRow]) -> func.HttpResp datetime.datetime.utcnow().isoformat("T", "milliseconds"), "test", "test", - "test", - "test") + "\u2649", + "\u2649") ) product.set(productColumnTypes) From bfbf9160b071f38f20005a41e8169bcd5ddd90b5 Mon Sep 17 00:00:00 2001 From: Lucy Zhang Date: Thu, 19 Jan 2023 13:36:10 -0800 Subject: [PATCH 13/13] fix space --- .../src/main/java/com/function/Common/ProductColumnTypes.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Integration/test-java/src/main/java/com/function/Common/ProductColumnTypes.java b/test/Integration/test-java/src/main/java/com/function/Common/ProductColumnTypes.java index 2e16b6bb1..2d13a40ae 100644 --- a/test/Integration/test-java/src/main/java/com/function/Common/ProductColumnTypes.java +++ b/test/Integration/test-java/src/main/java/com/function/Common/ProductColumnTypes.java @@ -4,7 +4,7 @@ * license information. */ - package com.function.Common; +package com.function.Common; import java.math.BigDecimal; import java.sql.Timestamp;