Skip to content

Fix AddProductColumnTypesTest for Java #644

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 3 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/SetupGuide_Java.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- [Array](#array)
- [Single Row](#single-row)
- [Trigger Binding](#trigger-binding)
- [Known Issues](#known-issues)

## Setup Function App

Expand Down Expand Up @@ -421,3 +422,9 @@ Note: This tutorial requires that a SQL database is setup as shown in [Create a
## Trigger Binding

> Trigger binding support is only available for in-proc C# functions at present.

## Known Issues
The [Azure Functions Java worker](https://github.com/Azure/azure-functions-java-worker) uses the [GSON library](https://github.com/google/gson) to serialize and deserialize data. Since we are unable to customize the GSON serializer in the Java worker, there are limitations with the default GSON serializer settings.
- GSON is unable to parse `DATE` and `TIME` values from the SQL table as `java.sql.Date` and `java.sql.Time` types. The current workaround is to use String. Tracking issue: https://github.com/Azure/azure-functions-sql-extension/issues/422.
- On Linux, `java.sql.Timestamp` type gets serialized with an extra comma, causing the upsertion to fail. The current workaround is to use String. Tracking issue: https://github.com/Azure/azure-functions-sql-extension/issues/521.

2 changes: 0 additions & 2 deletions test/Integration/SqlOutputBindingIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ public void AddProductArrayTest(SupportedLanguages lang)
/// <param name="lang">The language to run the test against</param>
[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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ public HttpResponseMessage run(
(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()).toString(),
new Timestamp(System.currentTimeMillis()).toString(),
new Timestamp(System.currentTimeMillis()).toString(),
new Timestamp(System.currentTimeMillis()).toString(),
new Timestamp(System.currentTimeMillis()).toString(),
new Time(System.currentTimeMillis()).toString(),
"test",
"test",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package com.function.Common;

import java.math.BigDecimal;
import java.sql.Timestamp;

public class ProductColumnTypes {
private int ProductId;
Expand All @@ -21,11 +20,11 @@ public class ProductColumnTypes {
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 String Date;
private String Datetime;
private String Datetime2;
private String DatetimeOffset;
private String SmallDatetime;
private String Time;
private String CharType;
private String Varchar;
Expand All @@ -36,8 +35,8 @@ 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, String time, String charType,
BigDecimal numeric, short smallInt, BigDecimal smallMoney, short tinyInt, double floatType, double real, String date,
String datetime, String datetime2, String datetimeOffset, String smallDatetime, String time, String charType,
String varchar, String nchar, String nvarchar, String binary, String varbinary) {
ProductId = productId;
BigInt = bigInt;
Expand Down Expand Up @@ -148,43 +147,43 @@ public void setReal(double real) {
Real = real;
}

public Timestamp getDate() {
public String getDate() {
return Date;
}

public void setDate(Timestamp date) {
public void setDate(String date) {
Date = date;
}

public Timestamp getDatetime() {
public String getDatetime() {
return Datetime;
}

public void setDatetime(Timestamp datetime) {
public void setDatetime(String datetime) {
Datetime = datetime;
}

public Timestamp getDatetime2() {
public String getDatetime2() {
return Datetime2;
}

public void setDatetime2(Timestamp datetime2) {
public void setDatetime2(String datetime2) {
Datetime2 = datetime2;
}

public Timestamp getDatetimeOffset() {
public String getDatetimeOffset() {
return DatetimeOffset;
}

public void setDatetimeOffset(Timestamp datetimeOffset) {
public void setDatetimeOffset(String datetimeOffset) {
DatetimeOffset = datetimeOffset;
}

public Timestamp getSmallDatetime() {
public String getSmallDatetime() {
return SmallDatetime;
}

public void setSmallDatetime(Timestamp smallDatetime) {
public void setSmallDatetime(String smallDatetime) {
SmallDatetime = smallDatetime;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.microsoft.azure.functions.annotation.HttpTrigger;
import com.microsoft.azure.functions.sql.annotation.SQLInput;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Optional;
import java.util.logging.Level;
Expand All @@ -40,22 +41,22 @@ public HttpResponseMessage run(
commandType = "Text",
connectionStringSetting = "SqlConnectionString")
ProductColumnTypes[] products,
ExecutionContext context) throws JsonProcessingException {
ExecutionContext context) throws JsonProcessingException, ParseException {

ObjectMapper mapper = new ObjectMapper();
SimpleDateFormat df = new SimpleDateFormat("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'SSSXXX");
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));
long date = df.parse(product.getDate()).getTime();
long datetime = df.parse(product.getDatetime()).getTime();
long datetime2 = df.parse(product.getDatetime2()).getTime();
long smallDateTime = df.parse(product.getSmallDatetime()).getTime();
int offset = Calendar.getInstance().getTimeZone().getOffset(df.parse(product.getDatetime()).getTime());
product.setDate(new Timestamp(date - offset).toString());
product.setDatetime(new Timestamp(datetime - offset).toString());
product.setDatetime2(new Timestamp(datetime2 - offset).toString());
product.setSmallDatetime(new Timestamp(smallDateTime - offset).toString());
context.getLogger().log(Level.INFO, mapper.writeValueAsString(product));
}
return request.createResponseBuilder(HttpStatus.OK).header("Content-Type", "application/json").body(mapper.writeValueAsString(products)).build();
Expand Down