Skip to content

Commit

Permalink
fixed dependency in sql tests, removed util methods of avatica
Browse files Browse the repository at this point in the history
  • Loading branch information
datomo committed May 28, 2024
1 parent b17ad20 commit 57f9939
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@
import java.util.Properties;
import org.polypheny.db.algebra.constant.ConformanceEnum;
import org.polypheny.db.util.Conformance;
import org.polypheny.db.util.avatica.ConnectionConfigImpl;


/**
* Implementation of {@link PolyphenyDbConnectionConfig}.
*/
public class PolyphenyDbConnectionConfigImpl extends ConnectionConfigImpl implements PolyphenyDbConnectionConfig {
public class PolyphenyDbConnectionConfigImpl implements PolyphenyDbConnectionConfig {

protected final Properties properties;

public PolyphenyDbConnectionConfigImpl( Properties properties ) {
super( properties );
this.properties = properties;
}


Expand Down
69 changes: 69 additions & 0 deletions core/src/main/java/org/polypheny/db/util/CoreUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@
import java.math.BigDecimal;
import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
import java.sql.Array;
import java.text.MessageFormat;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.stream.Collectors;
import org.polypheny.db.algebra.constant.Kind;
Expand All @@ -42,11 +47,29 @@
import org.polypheny.db.runtime.Resources;
import org.polypheny.db.type.PolyType;
import org.polypheny.db.type.PolyTypeFamily;
import org.polypheny.db.util.avatica.ArrayImpl;
import org.polypheny.db.util.avatica.Casing;
import org.polypheny.db.util.avatica.ColumnMetaData.AvaticaType;

public class CoreUtil {


private static final Map<Class<?>, Class<?>> BOX;


static {
BOX = new HashMap<>();
BOX.put( boolean.class, Boolean.class );
BOX.put( byte.class, Byte.class );
BOX.put( char.class, Character.class );
BOX.put( short.class, Short.class );
BOX.put( int.class, Integer.class );
BOX.put( long.class, Long.class );
BOX.put( float.class, Float.class );
BOX.put( double.class, Double.class );
}


/**
* Extracts the values from a collation name.
*
Expand Down Expand Up @@ -409,6 +432,52 @@ public static String trim( String s, String chars ) {
}


/**
* Adapts a primitive array into a {@link List}. For example,
* {@code asList(new double[2])} returns a {@code List&lt;Double&gt;}.
*/
public static List<?> primitiveList( final Object array ) {
// REVIEW: A per-type list might be more efficient. (Or might not.)
return new AbstractList<>() {
public Object get( int index ) {
return java.lang.reflect.Array.get( array, index );
}


public int size() {
return java.lang.reflect.Array.getLength( array );
}
};
}


/**
* Returns the boxed class. For example, {@code box(int.class)}
* returns {@code java.lang.Integer}.
*/
public static Class<?> box( Class<?> clazz ) {
if ( clazz.isPrimitive() ) {
return BOX.get( clazz );
}
return clazz;
}


public static Array createArray( AvaticaType elementType, Iterable<Object> elements ) {
// Avoid creating a new List if we already have a List
List<Object> elementList;
if ( elements instanceof List ) {
elementList = (List<Object>) elements;
} else {
elementList = new ArrayList<>();
for ( Object element : elements ) {
elementList.add( element );
}
}
return new ArrayImpl( elementList, elementType );
}


/**
* The components of a collation definition, per the SQL standard.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.List;
import java.util.Map;
import lombok.Getter;
import org.polypheny.db.util.CoreUtil;
import org.polypheny.db.util.avatica.ColumnMetaData.ArrayType;
import org.polypheny.db.util.avatica.ColumnMetaData.AvaticaType;
import org.polypheny.db.util.avatica.ColumnMetaData.Rep;
Expand Down Expand Up @@ -98,7 +99,7 @@ private void append( StringBuilder buf, Object o ) {
if ( o == null ) {
buf.append( "null" );
} else if ( o.getClass().isArray() ) {
append( buf, Utils.primitiveList( o ) );
append( buf, CoreUtil.primitiveList( o ) );
} else {
buf.append( o );
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.polypheny.db.util.CoreUtil;

/**
* Extends the information in {@link java.sql.Types}.
Expand Down Expand Up @@ -516,7 +517,7 @@ private static <E extends Enum<E>> EnumSet<E> concat( Collection<E>... ess ) {
* Returns the boxed type.
*/
public Class<?> boxedClass() {
return Utils.box( clazz );
return CoreUtil.box( clazz );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.Calendar;
import java.util.List;
import java.util.Objects;
import org.polypheny.db.util.CoreUtil;
import org.polypheny.db.util.avatica.ColumnMetaData.AvaticaType;
import org.polypheny.db.util.avatica.ColumnMetaData.Rep;
import org.polypheny.db.util.temporal.DateTimeUtils;
Expand Down Expand Up @@ -320,7 +321,7 @@ private static Object serialToJdbc(
assert componentRep != null;
AvaticaType elementType = new AvaticaType( componentRep.typeId, componentRep.name(),
componentRep );
return Utils.createArray( elementType, copy );
return CoreUtil.createArray( elementType, copy );
default:
return serialToLocal( type, value );
}
Expand Down
111 changes: 0 additions & 111 deletions core/src/main/java/org/polypheny/db/util/avatica/Utils.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
import org.junit.jupiter.api.Test;
import org.polypheny.db.TestHelper;
import org.polypheny.db.TestHelper.JdbcConnection;
import org.polypheny.db.util.CoreUtil;
import org.polypheny.db.util.avatica.ColumnMetaData;
import org.polypheny.db.util.avatica.ColumnMetaData.Rep;
import org.polypheny.db.util.avatica.SqlType;
import org.polypheny.db.util.avatica.Utils;


@SuppressWarnings({ "SqlDialectInspection", "SqlNoDataSourceInspection" })
Expand Down Expand Up @@ -1092,13 +1092,13 @@ public void arrayTest() throws SQLException {


preparedInsert.setInt( 1, 1 );
preparedInsert.setArray( 2, Utils.createArray(
preparedInsert.setArray( 2, CoreUtil.createArray(
ColumnMetaData.scalar( Types.INTEGER, "INTEGER", Rep.INTEGER ),
ImmutableList.of( 1, 2 ) ) );
preparedInsert.execute();

preparedInsert.setInt( 1, 2 );
preparedInsert.setArray( 2, Utils.createArray(
preparedInsert.setArray( 2, CoreUtil.createArray(
ColumnMetaData.scalar( Types.INTEGER, "INTEGER", Rep.INTEGER ),
ImmutableList.of( 4, 5 ) ) );
preparedInsert.execute();
Expand Down Expand Up @@ -1136,13 +1136,13 @@ public void arrayBatchTest() throws SQLException {


preparedInsert.setInt( 1, 1 );
preparedInsert.setArray( 2, Utils.createArray(
preparedInsert.setArray( 2, CoreUtil.createArray(
ColumnMetaData.scalar( Types.VARCHAR, "VARCHAR", Rep.STRING ),
ImmutableList.of( "Hans", "Georg" ) ) );
preparedInsert.addBatch();

preparedInsert.setInt( 1, 2 );
preparedInsert.setArray( 2, Utils.createArray(
preparedInsert.setArray( 2, CoreUtil.createArray(
ColumnMetaData.scalar( Types.VARCHAR, "VARCHAR", Rep.STRING ),
ImmutableList.of( "Lisa", "Livia" ) ) );
preparedInsert.addBatch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
import org.junit.jupiter.api.Test;
import org.polypheny.db.TestHelper;
import org.polypheny.db.TestHelper.JdbcConnection;
import org.polypheny.db.util.CoreUtil;
import org.polypheny.db.util.avatica.ColumnMetaData;
import org.polypheny.db.util.avatica.ColumnMetaData.Rep;
import org.polypheny.db.util.avatica.Utils;


@SuppressWarnings({ "SqlDialectInspection", "SqlNoDataSourceInspection" })
Expand Down Expand Up @@ -256,7 +256,7 @@ public void preparedStatementTest() throws SQLException {
try ( Statement statement = connection.createStatement() ) {
PreparedStatement preparedStatement = connection.prepareStatement( "SELECT id, distance(myarray, cast(? as INTEGER ARRAY), cast( ? as VARCHAR)) as dist FROM knninttest ORDER BY id" );

preparedStatement.setArray( 1, Utils.createArray(
preparedStatement.setArray( 1, CoreUtil.createArray(
ColumnMetaData.scalar( Types.INTEGER, "INTEGER", Rep.STRING ),
ImmutableList.of( 1, 1 ) ) );
preparedStatement.setString( 2, "L2SQUARED" );
Expand Down
Loading

0 comments on commit 57f9939

Please sign in to comment.