apache / apache/wayang

Automatically create calcite schema based on user provided configurations of tab...

Open
#294 0 comments 0 reactions 0 assignees View on GitHub
todo
Dominant language
Java
Stars
274
Forks
140
Avg merge
5d 16h
Merged PRs (30d)
4

Description

Automatically create calcite schema based on user provided configurations of table sources

https://github.com/apache/incubator-wayang/blob/d46f3c3f0fb963c2ee2640f00a106042fba55431/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/schema/SchemaUtils.java#L32

```java

/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you 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.wayang.api.sql.calcite.schema;

import org.apache.calcite.jdbc.CalciteConnection;
import org.apache.calcite.jdbc.CalciteSchema;
import org.apache.calcite.schema.SchemaPlus;
import org.apache.wayang.core.api.Configuration;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

/**
* This class contains some hardcoded functions for creating calcite schema.
* TODO: Automatically create calcite schema based on user provided configurations of table sources
*/
public class SchemaUtils {

private static Properties getPostgresProperties() {
/** Hardcoded for testing **/
Properties info = new Properties();
info.put("model",
"inline:"
+ "{\n"
+ " version: '1.0',\n"
+ " defaultSchema: 'tpch',\n"
+ " schemas: [\n"
+ " {\n"
+ " name: 'postgres',\n"
+ " type: 'custom',\n"
+ " factory: 'org.apache.wayang.api.sql.calcite.jdbc.JdbcSchema$Factory',\n"
+ " operand: {\n"
+ " jdbcDriver: 'org.postgresql.Driver',\n"
+ " jdbcUrl: 'jdbc:postgresql://localhost:5432/tpch',\n"
+ " jdbcUser: 'user',\n"
+ " jdbcPassword: 'password'\n"
+ " }\n"
+ " }\n"
+ " ]\n"
+ "}");
return info;
}

private static Properties getFileProperties() {
Properties info = new Properties();
info.put("model",
"inline:"
+ "{\n"
+ " version: '1.0',\n"
+ " defaultSchema: 'tpch',\n"
+ " schemas: [ {\n"
+ " name: 'fs',\n"
+ " type: 'custom',\n"
+ " factory: 'org.apache.calcite.adapter.file.FileSchemaFactory',\n"
+ " operand: {\n"
+ " directory: '/data/Projects/databloom/test-data'\n"
+ " } \n"
+ " }\n"
+ " ]\n"
+ "}"
);
return info;
}

public static CalciteSchema getPostgresSchema(Configuration configuration) throws SQLException {
final Connection connection = DriverManager.getConnection("jdbc:calcite:", getPostgresProperties());
return getCalciteSchema(connection);
}

public static CalciteSchema getFileSchema(Configuration configuration) throws SQLException {
final Connection connection = DriverManager.getConnection("jdbc:calcite:", getFileProperties());
return getCalciteSchema(connection);
}

public static CalciteSchema getCalciteSchema(Connection connection) throws SQLException {
CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
final SchemaPlus schemaPlus = calciteConnection.getRootSchema();
CalciteSchema calciteSchema = CalciteSchema.from(schemaPlus);
return calciteSchema;
}
}

```

0fdef9320b429e35c9ea27527ce773624c5b88da

Contributor guide

Open the contributing guide

Research direction

Start in wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/schema/SchemaUtils.java, especially getPostgresSchema, getFileSchema, and the Configuration parameter. Trace how the hardcoded Calcite properties describe table sources and determine how user-provided configurations should replace them. Done means Calcite schemas are created from those configurations rather than fixed PostgreSQL and file settings.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.