Skip to content

Commit

Permalink
GIS #462: upgraded Junit to v5 in geo tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danylokravchenko committed Dec 18, 2023
1 parent 5edb677 commit 508c34d
Show file tree
Hide file tree
Showing 4 changed files with 252 additions and 127 deletions.
137 changes: 137 additions & 0 deletions core/src/main/java/org/polypheny/db/type/entity/PolyTimestamp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* Copyright 2019-2023 The Polypheny Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.polypheny.db.type.entity;

import com.fasterxml.jackson.core.JsonToken;
import java.sql.Time;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Value;
import org.apache.calcite.linq4j.tree.Expression;
import org.apache.calcite.linq4j.tree.Expressions;
import org.apache.commons.lang3.NotImplementedException;
import org.jetbrains.annotations.NotNull;
import org.polypheny.db.functions.Functions;
import org.polypheny.db.type.PolySerializable;
import org.polypheny.db.type.PolyType;
import org.polypheny.db.type.entity.category.PolyTemporal;
import org.polypheny.db.util.TimestampString;

@Getter
@Value
@EqualsAndHashCode(callSuper = true)
public class PolyTimestamp extends PolyTemporal {

public static final DateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );

public Long milliSinceEpoch; // normalized to UTC


public PolyTimestamp( Long milliSinceEpoch ) {
super( PolyType.TIMESTAMP );
this.milliSinceEpoch = milliSinceEpoch;
}


public static PolyTimestamp of( Number number ) {
return new PolyTimestamp( number.longValue() );
}


public static PolyTimestamp ofNullable( Number number ) {
return number == null ? null : of( number );
}


public static PolyTimestamp ofNullable( Time value ) {
return value == null ? null : PolyTimestamp.of( value );
}


public static PolyTimestamp of( long value ) {
return new PolyTimestamp( value );
}


public static PolyTimestamp of( Long value ) {
return new PolyTimestamp( value );
}


public static PolyTimestamp of( Timestamp value ) {
return new PolyTimestamp( Functions.toLongOptional( value ) );
}


public static PolyTimestamp of( Date date ) {
return new PolyTimestamp( date.getTime() );
}


public Timestamp asSqlTimestamp() {
return new Timestamp( milliSinceEpoch );
}


@Override
public String toJson() {
return milliSinceEpoch == null ? JsonToken.VALUE_NULL.asString() : TimestampString.fromMillisSinceEpoch( milliSinceEpoch ).toString();
}


@Override
public int compareTo( @NotNull PolyValue o ) {
if ( !isSameType( o ) ) {
return -1;
}

return Long.compare( milliSinceEpoch, o.asTimestamp().milliSinceEpoch );
}


@Override
public Expression asExpression() {
return Expressions.new_( PolyTimestamp.class, Expressions.constant( milliSinceEpoch ) );
}


@Override
public PolySerializable copy() {
return PolySerializable.deserialize( serialize(), PolyTimestamp.class );
}


public static PolyTimestamp convert( PolyValue value ) {
if ( value.isNumber() ) {
return PolyTimestamp.of( value.asNumber().longValue() );
} else if ( value.isTemporal() ) {
return PolyTimestamp.of( value.asTemporal().getMilliSinceEpoch() );
}
throw new NotImplementedException( "convert " + PolyTimestamp.class.getSimpleName() );
}


@Override
public @NotNull Long deriveByteSize() {
return 16L;
}

}
2 changes: 1 addition & 1 deletion dbms/src/main/java/org/polypheny/db/PolyphenyDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public class PolyphenyDb {
public boolean daemonMode = false;

@Option(name = { "-defaultStore" }, description = "Type of default storeId")
public String defaultStoreName = "mongodb";
public String defaultStoreName = "hsqldb";

@Option(name = { "-defaultSource" }, description = "Type of default source")
public String defaultSourceName = "csv";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,19 @@
import java.sql.SQLException;
import java.sql.Statement;
import lombok.extern.slf4j.Slf4j;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.polypheny.db.AdapterTestSuite;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.polypheny.db.TestHelper;
import org.polypheny.db.TestHelper.JdbcConnection;

@SuppressWarnings({ "SqlDialectInspection", "SqlNoDataSourceInspection" })
@Slf4j
@Category({ AdapterTestSuite.class })
@Tag("adapter")
public class GeoFunctionsTest {

@BeforeClass
@BeforeAll
public static void start() throws SQLException {
// Ensures that Polypheny-DB is running
//noinspection ResultOfMethodCallIgnored
Expand All @@ -55,7 +54,7 @@ private static void addTestData() throws SQLException {
}


@AfterClass
@AfterAll
public static void stop() throws SQLException {
try ( JdbcConnection jdbcConnection = new JdbcConnection( true ) ) {
Connection connection = jdbcConnection.getConnection();
Expand Down
Loading

0 comments on commit 508c34d

Please sign in to comment.