Skip to content

Commit

Permalink
let there be SQl results
Browse files Browse the repository at this point in the history
  • Loading branch information
datomo committed Sep 9, 2023
1 parent bb04865 commit d79f94b
Show file tree
Hide file tree
Showing 12 changed files with 185 additions and 323 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ public List<List<T>> getRows() {
List<List<T>> res = new ArrayList<>();
int i = 0;
while ( i++ < batch && iterator.hasNext() ) {
res.add( List.of( (T[]) iterator.next() ) );
res.add( rowType.getFieldCount() == 1 ? List.of( iterator.next() ) : List.of( (T[]) iterator.next() ) );
}

//List<List<T>> res = MetaImpl.collect( cursorFactory, (Iterator<Object>) iterator., new ArrayList<>() ).stream().map( e -> (List<T>) e ).collect( Collectors.toList() );
Expand Down
14 changes: 2 additions & 12 deletions core/src/main/java/org/polypheny/db/type/PolyType.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializer;
import java.math.BigDecimal;
import java.sql.Types;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
import java.util.Set;
import lombok.Getter;
import org.apache.calcite.avatica.util.TimeUnit;
import org.polypheny.db.util.Util;

Expand Down Expand Up @@ -527,6 +526,7 @@ public enum PolyType {
/**
* Bitwise-or of flags indicating allowable precision/scale combinations.
*/
@Getter
private final int signatures;

/**
Expand Down Expand Up @@ -1228,15 +1228,5 @@ private interface PrecScale {
int YES_YES = 4;

}


public static JsonSerializer<PolyType> getSerializer() {
return ( src, typeOfSrc, context ) -> {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty( "name", src.name() );
jsonObject.addProperty( "signatures", src.signatures );
return jsonObject;
};
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import com.fasterxml.jackson.annotation.JsonInclude;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;
Expand All @@ -31,7 +30,6 @@
import java.io.IOException;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.jetty.websocket.api.Session;
import org.jetbrains.annotations.NotNull;
import org.polypheny.db.StatusService;
import org.polypheny.db.information.InformationAction;
import org.polypheny.db.information.InformationManager;
Expand All @@ -46,7 +44,6 @@
@Slf4j
public class InformationServer implements InformationObserver {

private static final Gson gson;
public static final TypeAdapterFactory throwableTypeAdapterFactory;
public static final TypeAdapter<Throwable> throwableTypeAdapter;

Expand Down Expand Up @@ -82,7 +79,6 @@ public Throwable read( JsonReader in ) throws IOException {
return new Throwable( in.nextString() );
}
};
gson = new GsonBuilder().registerTypeAdapterFactory( throwableTypeAdapterFactory ).create();
}


Expand Down
33 changes: 17 additions & 16 deletions webui/src/main/java/org/polypheny/db/webui/Crud.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.google.common.collect.ImmutableMap;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
Expand All @@ -44,9 +43,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.Array;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
Expand Down Expand Up @@ -174,6 +171,8 @@
import org.polypheny.db.webui.crud.StatisticCrud;
import org.polypheny.db.webui.models.DbTable;
import org.polypheny.db.webui.models.ForeignKey;
import org.polypheny.db.webui.models.IndexAdapterModel;
import org.polypheny.db.webui.models.IndexAdapterModel.IndexMethodModel;
import org.polypheny.db.webui.models.IndexModel;
import org.polypheny.db.webui.models.MaterializedInfos;
import org.polypheny.db.webui.models.Namespace;
Expand All @@ -191,6 +190,7 @@
import org.polypheny.db.webui.models.UnderlyingTables;
import org.polypheny.db.webui.models.catalog.AdapterModel;
import org.polypheny.db.webui.models.catalog.AdapterModel.AdapterSettingValueModel;
import org.polypheny.db.webui.models.catalog.PolyTypeModel;
import org.polypheny.db.webui.models.catalog.UiColumnDefinition;
import org.polypheny.db.webui.models.requests.BatchUpdateRequest;
import org.polypheny.db.webui.models.requests.BatchUpdateRequest.Update;
Expand Down Expand Up @@ -2136,20 +2136,21 @@ void getAvailableStoresForIndexes( final Context ctx ) {
IndexModel index = ctx.bodyAsClass( IndexModel.class );
PlacementModel dataPlacements = getPlacements( index );
Map<String, DataStore<?>> stores = AdapterManager.getInstance().getStores();
//see https://stackoverflow.com/questions/18857884/how-to-convert-arraylist-of-custom-class-to-jsonarray-in-java
JsonArray jsonArray = HttpServer.gson.toJsonTree( stores.values().stream().filter( ( s ) -> {
List<IndexAdapterModel> filtered = stores.values().stream().filter( ( s ) -> {
if ( s.getAvailableIndexMethods() == null || s.getAvailableIndexMethods().isEmpty() ) {
return false;
}
return dataPlacements.stores.stream().anyMatch( ( dp ) -> dp.uniqueName.equals( s.getUniqueName() ) );
} ).toArray( DataStore[]::new ) ).getAsJsonArray();
} ).map( IndexAdapterModel::from ).collect( Collectors.toCollection( ArrayList::new ) );

if ( RuntimeConfig.POLYSTORE_INDEXES_ENABLED.getBoolean() ) {
JsonObject pdbFakeStore = new JsonObject();
pdbFakeStore.addProperty( "uniqueName", "Polypheny-DB" );
pdbFakeStore.add( "availableIndexMethods", HttpServer.gson.toJsonTree( IndexManager.getAvailableIndexMethods() ) );
jsonArray.add( pdbFakeStore );
IndexAdapterModel poly = new IndexAdapterModel(
-1L,
"Polypheny-DB",
IndexManager.getAvailableIndexMethods().stream().map( IndexMethodModel::from ).collect( Collectors.toList() ) );
filtered.add( poly );
}
ctx.json( jsonArray );
ctx.json( filtered );
}


Expand Down Expand Up @@ -2233,7 +2234,7 @@ void getSources( final Context ctx ) {
/**
* Deploy a new adapter
*/
void addAdapter( final Context ctx ) throws ServletException, IOException {
void addAdapter( final Context ctx ) {
AdapterModel a = ctx.bodyAsClass( AdapterModel.class );
Map<String, String> settings = new HashMap<>();

Expand Down Expand Up @@ -2815,7 +2816,7 @@ else if ( !namespace.isCreate() && namespace.isDrop() ) {
* Get all supported data types of the DBMS.
*/
public void getTypeInfo( final Context ctx ) {
ctx.json( PolyType.availableTypes().toArray( new PolyType[0] ) );
ctx.json( PolyType.availableTypes().stream().map( t -> PolyTypeModel.from( t ) ).collect( Collectors.toList() ) );
}


Expand Down Expand Up @@ -3211,8 +3212,8 @@ public static List<String[]> computeResultData( final List<List<PolyValue>> rows
default:
temp[counter] = o.toString();
}*/
temp[counter] = o.toString();
if ( header.get( counter ).dataType.endsWith( "ARRAY" ) ) {
temp[counter] = o.toJson();
/*if ( header.get( counter ).dataType.endsWith( "ARRAY" ) ) {
if ( o instanceof Array ) {
try {
temp[counter] = gson.toJson( ((Array) o).getArray(), Object[].class );
Expand All @@ -3228,7 +3229,7 @@ public static List<String[]> computeResultData( final List<List<PolyValue>> rows
}
if ( header.get( counter ).dataType.contains( "Path" ) ) {
temp[counter] = o.toJson();
}
}*/
}
counter++;
}
Expand Down
23 changes: 6 additions & 17 deletions webui/src/main/java/org/polypheny/db/webui/HttpServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@


import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.TypeAdapter;
Expand All @@ -39,22 +40,10 @@
import java.util.function.Consumer;
import lombok.extern.slf4j.Slf4j;
import org.polypheny.db.StatusService;
import org.polypheny.db.adapter.AbstractAdapterSetting;
import org.polypheny.db.adapter.AdapterManager.AdapterInformation;
import org.polypheny.db.adapter.AdapterSettingDeserializer;
import org.polypheny.db.adapter.DataSource;
import org.polypheny.db.adapter.DataStore;
import org.polypheny.db.catalog.Catalog;
import org.polypheny.db.config.RuntimeConfig;
import org.polypheny.db.iface.Authenticator;
import org.polypheny.db.information.InformationDuration;
import org.polypheny.db.information.InformationDuration.Duration;
import org.polypheny.db.information.InformationGroup;
import org.polypheny.db.information.InformationPage;
import org.polypheny.db.information.InformationStacktrace;
import org.polypheny.db.plugins.PolyPluginManager.PluginStatus;
import org.polypheny.db.transaction.TransactionManager;
import org.polypheny.db.type.PolyType;
import org.polypheny.db.webui.crud.LanguageCrud;
import org.polypheny.db.webui.models.results.RelationalResult;

Expand All @@ -68,7 +57,6 @@ public class HttpServer implements Runnable {
private final TransactionManager transactionManager;
private final Authenticator authenticator;

public static final Gson gson;
private final Gson gsonExpose = new GsonBuilder()
.excludeFieldsWithoutExposeAnnotation()
.enableComplexMapKeySerialization()
Expand Down Expand Up @@ -98,12 +86,11 @@ public Throwable read( JsonReader in ) throws IOException {
return new Throwable( in.nextString() );
}
};
gson = new GsonBuilder()
/*gson = new GsonBuilder()
.enableComplexMapKeySerialization()
.registerTypeHierarchyAdapter( DataSource.class, DataSource.getSerializer() )
.registerTypeHierarchyAdapter( DataStore.class, DataStore.getSerializer() )
.registerTypeHierarchyAdapter( Throwable.class, throwableTypeAdapter )
.registerTypeAdapter( PolyType.class, PolyType.getSerializer() )
.registerTypeAdapter( AdapterInformation.class, AdapterInformation.getSerializer() )
.registerTypeAdapter( AbstractAdapterSetting.class, new AdapterSettingDeserializer() )
.registerTypeAdapter( InformationDuration.class, InformationDuration.getSerializer() )
Expand All @@ -113,7 +100,7 @@ public Throwable read( JsonReader in ) throws IOException {
.registerTypeAdapter( InformationGroup.class, InformationGroup.getSerializer() )
.registerTypeAdapter( InformationStacktrace.class, InformationStacktrace.getSerializer() )
.registerTypeAdapter( PluginStatus.class, PluginStatus.getSerializer() )
.create();
.create();*/
}


Expand Down Expand Up @@ -149,6 +136,8 @@ public void run() {
config.http.maxRequestSize = maxRequestSize;
config.jsonMapper( new JavalinJackson().updateMapper( mapper -> {
mapper.setSerializationInclusion( JsonInclude.Include.NON_NULL );
mapper.configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false );
mapper.writerWithDefaultPrettyPrinter();
} ) );
} ).start( RuntimeConfig.WEBUI_SERVER_PORT.getInteger() );

Expand All @@ -157,7 +146,7 @@ public void run() {
Catalog.defaultUserId,
Catalog.defaultNamespaceId );

WebSocket webSocketHandler = new WebSocket( crud, gson );
WebSocket webSocketHandler = new WebSocket( crud );
webSockets( server, webSocketHandler );

// Get modified index.html
Expand Down
5 changes: 1 addition & 4 deletions webui/src/main/java/org/polypheny/db/webui/WebSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.polypheny.db.webui;


import com.google.gson.Gson;
import io.javalin.websocket.WsCloseContext;
import io.javalin.websocket.WsConfig;
import io.javalin.websocket.WsConnectContext;
Expand Down Expand Up @@ -53,12 +52,10 @@ public class WebSocket implements Consumer<WsConfig> {
private static final Queue<Session> sessions = new ConcurrentLinkedQueue<>();
private final Crud crud;
private final ConcurrentHashMap<String, Set<String>> queryAnalyzers = new ConcurrentHashMap<>();
private final Gson gson;


WebSocket( Crud crud, Gson gson ) {
WebSocket( Crud crud ) {
this.crud = crud;
this.gson = gson;
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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.webui.models;

import java.util.List;
import java.util.stream.Collectors;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Value;
import org.jetbrains.annotations.Nullable;
import org.polypheny.db.adapter.DataStore;
import org.polypheny.db.adapter.DataStore.AvailableIndexMethod;
import org.polypheny.db.webui.models.catalog.IdEntity;

@EqualsAndHashCode(callSuper = true)
@Value
public class IndexAdapterModel extends IdEntity {

public List<IndexMethodModel> availableIndexMethods;


public IndexAdapterModel( @Nullable Long id, @Nullable String name, List<IndexMethodModel> availableIndexMethods ) {
super( id, name );
this.availableIndexMethods = availableIndexMethods;
}


public static IndexAdapterModel from( DataStore<?> store ) {
return new IndexAdapterModel( store.adapterId, store.getUniqueName(), store.getAvailableIndexMethods().stream().map( IndexMethodModel::from ).collect( Collectors.toList() ) );
}


@AllArgsConstructor
public static class IndexMethodModel {

public String name;
public String displayName;


public static IndexMethodModel from( AvailableIndexMethod index ) {
return new IndexMethodModel( index.name, index.displayName );
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.webui.models.catalog;

import lombok.Value;
import org.polypheny.db.type.PolyType;

@Value
public class PolyTypeModel {

public String name;

public int signatures;


public PolyTypeModel( String name, int signatures ) {
this.name = name;
this.signatures = signatures;
}


public static PolyTypeModel from( PolyType type ) {
return new PolyTypeModel( type.name(), type.getSignatures() );
}

}
Loading

0 comments on commit d79f94b

Please sign in to comment.