github-code-scanning[bot] commented on code in PR #709: URL: https://github.com/apache/incubator-baremaps/pull/709#discussion_r1235947386
########## baremaps-core/src/main/java/org/apache/baremaps/calcite/Calcite.java: ########## @@ -0,0 +1,133 @@ +/* + * 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.apache.baremaps.calcite; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; +import java.util.Properties; +import org.apache.baremaps.collection.AppendOnlyBuffer; +import org.apache.baremaps.collection.IndexedDataList; +import org.apache.baremaps.collection.store.*; +import org.apache.baremaps.collection.type.RowDataType; +import org.apache.calcite.DataContext; +import org.apache.calcite.jdbc.CalciteConnection; +import org.apache.calcite.jdbc.JavaTypeFactoryImpl; +import org.apache.calcite.linq4j.Enumerable; +import org.apache.calcite.linq4j.Linq4j; +import org.apache.calcite.rel.type.RelDataType; +import org.apache.calcite.rel.type.RelDataTypeFactory; +import org.apache.calcite.schema.ScannableTable; +import org.apache.calcite.schema.SchemaPlus; +import org.apache.calcite.schema.impl.AbstractTable; +import org.apache.calcite.sql.type.SqlTypeName; + +public class Calcite { + + private static final Schema PLAYER_SCHEMA = new SchemaImpl("player", List.of( + new ColumnImpl("id", Integer.class), + new ColumnImpl("name", String.class), + new ColumnImpl("level", Integer.class))); + + private static final Table PLAYER_TABLE = new TableImpl( + PLAYER_SCHEMA, + new IndexedDataList<>(new AppendOnlyBuffer<>(new RowDataType(PLAYER_SCHEMA)))); + + static { + PLAYER_TABLE.add(new RowImpl(PLAYER_TABLE.schema(), List.of(1, "Wizard", 5))); + PLAYER_TABLE.add(new RowImpl(PLAYER_TABLE.schema(), List.of(2, "Hunter", 7))); + } + + private static final Schema EQUIPMENT_SCHEMA = new SchemaImpl("equipment", List.of( + new ColumnImpl("id", Integer.class), + new ColumnImpl("name", String.class), + new ColumnImpl("damage", Integer.class), + new ColumnImpl("player_id", Integer.class))); + + private static final Table EQUIPMENT_TABLE = new TableImpl( + EQUIPMENT_SCHEMA, + new IndexedDataList<>(new AppendOnlyBuffer<>(new RowDataType(EQUIPMENT_SCHEMA)))); + + static { + EQUIPMENT_TABLE.add(new RowImpl(EQUIPMENT_TABLE.schema(), List.of(1, "fireball", 7, 1))); + EQUIPMENT_TABLE.add(new RowImpl(EQUIPMENT_TABLE.schema(), List.of(2, "rifle", 4, 2))); + } + + public static void main(String[] args) throws SQLException { + Properties info = new Properties(); + info.setProperty("lex", "MYSQL"); + + Connection connection = DriverManager.getConnection("jdbc:calcite:", info); + CalciteConnection calciteConnection = + connection.unwrap(CalciteConnection.class); + + SchemaPlus rootSchema = calciteConnection.getRootSchema(); + + ListTable playerTable = new ListTable(PLAYER_TABLE); + rootSchema.add("player", playerTable); + + ListTable equipmentTable = new ListTable(EQUIPMENT_TABLE); + rootSchema.add("equipment", equipmentTable); + + String sql = + "SELECT player.name, equipment.name FROM player INNER JOIN equipment ON player.id = equipment.player_id "; + ResultSet resultSet = connection.createStatement().executeQuery(sql); Review Comment: ## Potential database resource leak This Statement is not always closed on method exit. [Show more details](https://github.com/apache/incubator-baremaps/security/code-scanning/685) ########## baremaps-core/src/main/java/org/apache/baremaps/collection/store/SchemaImpl.java: ########## @@ -10,15 +10,42 @@ * the License. */ -package org.apache.baremaps.storage; +package org.apache.baremaps.collection.store; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * A schema defines the structure of a table. */ -public record SchemaImpl(String name, List<Column> columns) implements Schema { +public class SchemaImpl implements Schema { + + private final String name; + + private final List<Column> columns; + + private final Map<String, Integer> index; Review Comment: ## Container contents are never accessed The contents of this container are never accessed. [Show more details](https://github.com/apache/incubator-baremaps/security/code-scanning/684) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
