Skip to content

Commit

Permalink
remove unused fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Hafner committed Sep 19, 2023
1 parent bf7fc16 commit 80dc9e5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.polypheny.db.protointerface.relational;

import com.google.common.collect.ImmutableBiMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
Expand All @@ -43,29 +42,18 @@

public class RelationalMetaRetriever {

private static final String PROTO_VALUE_TYPE_PREFIX = "PROTO_VALUE_TYPE_";
private static final int ORIGIN_COLUMN_INDEX = 3;
private static final int ORIGIN_TABLE_INDEX = 2;
private static final int ORIGIN_SCHEMA_INDEX = 1;
private static final int ORIGIN_DATABASE_INDEX = 0;


public static List<ParameterMeta> retrieveParameterMetas( AlgDataType parameterRowType ) {
int index = 0;
return parameterRowType.getFieldList().stream()
.map( p -> retrieveParameterMeta( p, null ) )
.collect( Collectors.toList() );
}


public static List<ParameterMeta> retrieveParameterMetas( AlgDataType parameterRowType, ImmutableBiMap<String, Integer> namedIndexes ) {
int index = 0;
return parameterRowType.getFieldList().stream()
.map( p -> retrieveParameterMeta( p, namedIndexes.inverse().get( index ) ) )
.collect( Collectors.toList() );
}


private static ParameterMeta retrieveParameterMeta( AlgDataTypeField algDataTypeField, String parameterName ) {
AlgDataType algDataType = algDataTypeField.getType();
ParameterMeta.Builder metaBuilder = ParameterMeta.newBuilder();
Expand Down Expand Up @@ -110,19 +98,19 @@ private static ColumnMeta retrieveColumnMeta(
return columnMetaBuilder
.setColumnIndex( index )
.setColumnName( fieldName ) // designated column name
.setColumnLabel( getColumnLabel( origins, type, fieldName ) ) // alias as specified in sql AS clause
.setColumnLabel( getColumnLabel( origins, fieldName ) ) // alias as specified in sql AS clause
.setIsNullable( type.isNullable() )
.setLength( type.getPrecision() )
.setPrecision( QueryProcessorHelpers.getPrecision( type ) ) // <- same as type.getPrecision() but returns 0 if not applicable
.setScale( type.getScale() )
.setTypeMeta( typeMeta )
//.setNamespace()
//TODO TH: find out how to get namespace form here
//TODO: find out how to get namespace form here
.build();
}


private static String getColumnLabel( List<String> origins, AlgDataType type, String fieldName ) {
private static String getColumnLabel( List<String> origins, String fieldName ) {
String columnLabel = QueryProcessorHelpers.origin( origins, ORIGIN_COLUMN_INDEX );
return columnLabel == null ? fieldName : columnLabel;
}
Expand Down Expand Up @@ -180,16 +168,15 @@ private static TypeMeta retrieveTypeMeta( AlgDataType algDataType ) {

private static AlgDataType retrieveAlgDataType( PolyImplementation polyImplementation ) {
switch ( polyImplementation.getKind() ) {
case INSERT:
case DELETE:
case UPDATE:
case EXPLAIN:
case INSERT, DELETE, UPDATE, EXPLAIN -> {
// FIXME: getValidatedNodeType is wrong for DML
Kind kind = polyImplementation.getKind();
JavaTypeFactory typeFactory = polyImplementation.getStatement().getTransaction().getTypeFactory();
return AlgOptUtil.createDmlRowType( kind, typeFactory );
default:
}
default -> {
return polyImplementation.getRowType();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,6 @@ public static Frame fetch( PIStatement piStatement, int fetchSize ) {
return executor.fetch( piStatement, fetchSize );
}


public static Frame fetchGraphFrame( PIStatement piStatement ) {
throw new RuntimeException( "Feature not implemented" );
/*
Statement statement = piStatement.getStatement();
PolyImplementation<PolyValue> implementation = piStatement.getImplementation();
//TODO TH: Whats the actual type here?
List<PolyValue[]> data = implementation.getArrayRows( statement, true );
return ProtoUtils.buildGraphFrame();
*/
}


public static void prepare( PIPreparedStatement piStatement ) {
Transaction transaction = piStatement.getClient().getCurrentOrCreateNewTransaction();
String query = piStatement.getQuery();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.polypheny.db.protointerface;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -58,8 +59,8 @@ public class PolyValueSerializationTest {

@BeforeClass
public static void init() {
// needed to launch polypheny
TestHelper.getInstance();

}

private enum TestEnum {
Expand Down Expand Up @@ -125,7 +126,7 @@ public void polyBigDecimalSeriaizationTest() {
public void polyBinarySerializationTest() {
PolyBinary expected = PolyBinary.of( new byte[]{ 0x01, 0x02, 0x03 } );
ProtoValue protoValue = PolyValueSerializer.serialize( expected );
assertEquals( new byte[]{ 0x01, 0x02, 0x03 }, protoValue.getBinary().toByteArray() );
assertArrayEquals( new byte[]{ 0x01, 0x02, 0x03 }, protoValue.getBinary().toByteArray() );
}


Expand Down Expand Up @@ -177,13 +178,6 @@ public void polyIntegerSerializationTest() {
assertEquals( 1234, protoValue.getInteger().getInteger() );
}


@Test
public void polyIntervalSerializationTest() {
//TODO TH: create test
}


@Test
public void polyListSerializationTest() {
PolyList<PolyInteger> expected = new PolyList(
Expand All @@ -193,10 +187,10 @@ public void polyListSerializationTest() {
new PolyInteger( 4 )
);
List<ProtoValue> protoValues = PolyValueSerializer.serialize( expected ).getList().getValuesList();
assertEquals( 1, protoValues.get( 1 ).getInteger().getInteger() );
assertEquals( 2, protoValues.get( 2 ).getInteger().getInteger() );
assertEquals( 3, protoValues.get( 3 ).getInteger().getInteger() );
assertEquals( 4, protoValues.get( 4 ).getInteger().getInteger() );
assertEquals( 1, protoValues.get( 0 ).getInteger().getInteger() );
assertEquals( 2, protoValues.get( 1 ).getInteger().getInteger() );
assertEquals( 3, protoValues.get( 2 ).getInteger().getInteger() );
assertEquals( 4, protoValues.get( 3 ).getInteger().getInteger() );
}


Expand All @@ -208,31 +202,13 @@ public void polyLongSerializationTest() {
}


@Test
public void polyStreamSerializationTest() {
ByteArrayInputStream stream = new ByteArrayInputStream( "test data".getBytes() );
PolyStream expected = new PolyStream( stream );
ProtoValue protoValue = PolyValueSerializer.serialize( expected );
//TODO TH: create test
}


@Test
public void polyStringSerializationTest() {
PolyString expected = new PolyString( "sample string" );
ProtoValue protoValue = PolyValueSerializer.serialize( expected );
assertEquals( "sample string", protoValue.getString().getString() );
}


@Test
public void polySymbolSerializationTest() {
PolySymbol expected = new PolySymbol( TestEnum.UNTESTED );
ProtoValue protoValue = PolyValueSerializer.serialize( expected );
//TODO TH: create test
}


@Test
public void polyTimeSerializationTest() {
PolyTime expected = PolyTime.of( new Time( 1691879380700L ) );
Expand All @@ -248,15 +224,6 @@ public void polyTimeStampSerializationTest() {
assertEquals( 1691879380700L, protoValue.getTimeStamp().getTimeStamp() );
}


@Test
public void polyUserDefinedValueSerializationTest() {
PolyUserDefinedValue expected = buildTestUdt();
ProtoValue protoValue = PolyValueSerializer.serialize( expected );
//TODO TH: create test
}


@Test
public void polyBigDecimalSerializationCorrectTypeTest() {
PolyBigDecimal expected = new PolyBigDecimal( new BigDecimal( 1691879380700L ) );
Expand Down Expand Up @@ -391,7 +358,6 @@ public void polySymbolSerializationCorrectTypeTest() {
PolySymbol expected = new PolySymbol( TestEnum.UNTESTED );
ProtoValue protoValue = PolyValueSerializer.serialize( expected );
assertEquals( ProtoValueType.SYMBOL, protoValue.getType() );

}


Expand Down

0 comments on commit 80dc9e5

Please sign in to comment.