[ 
https://issues.apache.org/jira/browse/CALCITE-1951?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16131444#comment-16131444
 ] 

Francis Chuang commented on CALCITE-1951:
-----------------------------------------

This is the current test that is running against Phoenix and passes: 
https://github.com/apache/calcite-avatica-go/blob/master/driver_test.go#L392

This is the test (simplied) against HSQLDB that demonstrates this problem:

{code}
func TestHSQLDBLocations(t *testing.T) {
        query := "?location=Australia/Melbourne"

        runTests(t, dsn+query, func(dbt *DBTest) {

                // Create and seed table
                dbt.mustExec(`CREATE TABLE ` + dbt.tableName + ` (
                                tm TIME(6) PRIMARY KEY,
                                dt DATE,
                                tmstmp TIMESTAMP
                            )`)

                loc, err := time.LoadLocation("Australia/Melbourne")

                if err != nil {
                        dbt.Fatalf("Unexpected error: %s", err)
                }

                var (
                        tmValue     time.Time = time.Date(0, 1, 1, 21, 21, 21, 
222000000, loc)
                        dtValue     time.Time = time.Date(2100, 2, 1, 0, 0, 0, 
0, loc)
                        tmstmpValue time.Time = time.Date(2100, 2, 1, 21, 21, 
21, 222000000, loc)
                )

                dbt.mustExec(`INSERT INTO `+dbt.tableName+`(tm, dt, tmstmp) 
VALUES (?, ?, ?)`,
                        tmValue,
                        dtValue,
                        tmstmpValue,
                )

                rows := dbt.mustQuery("SELECT * FROM " + dbt.tableName)
                defer rows.Close()

                var (
                        tm     time.Time
                        dt     time.Time
                        tmstmp time.Time
                )

                for rows.Next() {

                        err := rows.Scan(&tm, &dt, &tmstmp)

                        if err != nil {
                                dbt.Fatal(err)
                        }
                }

                comparisons := []struct {
                        result   time.Time
                        expected time.Time
                }{
                        {tm, tmValue},
                        {dt, dtValue},
                        {tmstmp, tmstmpValue},
                }

                for _, tt := range comparisons {
                        if !tt.result.Equal(tt.expected) {
                                dbt.Errorf("Expected %v, got %v.", tt.expected, 
tt.result)
                        }
                }
        })
}
{code}

The comparison for date and timestamp works correctly. However, the comparison 
for time fails as the selected value loses the fractional seconds.

According to the guide on data types 
(http://hsqldb.org/doc/2.0/guide/sqlgeneral-chapt.html#sgc_data_type_guide), 
defining a field as TIME(6) should have 6 fractional seconds for the field. By 
default it is 0, but I've set it to 6 in my table definition.

> Avatica HSQLDB docker image time loses fractional seconds
> ---------------------------------------------------------
>
>                 Key: CALCITE-1951
>                 URL: https://issues.apache.org/jira/browse/CALCITE-1951
>             Project: Calcite
>          Issue Type: Bug
>          Components: avatica
>            Reporter: Francis Chuang
>            Assignee: Josh Elser
>
> I create a table like so in HSQLDB using the avatica-hsqldb image:
> {code}
> CREATE TABLE some_table (
>       tm TIME(6) PRIMARY KEY,
> )
> {code}
> I then use calculate the milliseconds since 00:00:00.000 and send this value 
> along with my insert statement: 76881222
> However, when I select the row to read the value back, I get 76881000.
> In this case, 222 milliseconds was lost.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to