// Path: journalled-sql-rewriter/src/main/java/org/apache/calcite/adapter/jdbc/JdbcTableUtils.java
// @SuppressWarnings("WeakerAccess") // Public API
// public class JdbcTableUtils {
// 	private JdbcTableUtils() {
// 		throw new UnsupportedOperationException();
// 	}
// 
// 	private static Object get(Class<?> clazz, Object object, String fieldName) {
// 		try {
// 			Field field = clazz.getDeclaredField(fieldName);
// 			field.setAccessible(true);
// 			return field.get(object);
// 		}
// 		catch (NoSuchFieldException | IllegalAccessException e) {
// 			throw new RuntimeException(e);
// 		}
// 	}
// 
// 	static JdbcTable getJdbcTable(RelNode originalRel) {
// 		return (JdbcTable) get(RelOptTableImpl.class, originalRel.getTable(), "table");
// 	}
// 
// 	static String getCatalogName(JdbcTable table) {
// 		return (String) get(JdbcTable.class, table, "jdbcCatalogName");
// 	}
// 
// 	static String getSchemaName(JdbcTable table) {
// 		return (String) get(JdbcTable.class, table, "jdbcSchemaName");
// 	}
// 
// 	static String getTableName(JdbcTable table) {
// 		// tableName is: [catalog,] [schema,] table
// 		SqlIdentifier identifier = table.tableName();
// 		return identifier.names.get(identifier.names.size() - 1);
// 	}
// 
// 	public static List<String> getQualifiedName(RelOptTable sibling, Table table) {
// 		if (!(table instanceof JdbcTable)) {
// 			throw new UnsupportedOperationException();
// 		}
// 
// 		List<String> name = new ArrayList<>();
// 		if (sibling != null) {
// 			name.addAll(sibling.getQualifiedName());
// 			name.remove(name.size() - 1);
// 		}
// 		name.add(getTableName((JdbcTable) table));
// 		return name;
// 	}
// 
// 	static RelNode toRel(RelOptCluster cluster, RelOptSchema relOptSchema, JdbcTable table, List<String> qualifiedName) {
// 		RelOptTable.ToRelContext toRelContext = new RelOptTable.ToRelContext() {
// 			@Override
// 			public RelOptCluster getCluster() {
// 				return cluster;
// 			}
// 
// 			@Override
// 			public RelRoot expandView(RelDataType rowType, String queryString, List<String> schemaPath, List<String> viewPath) {
// 				throw new UnsupportedOperationException();
// 			}
// 		};
// 
// 		return table.toRel(
// 				toRelContext,
// 				relOptSchema.getTableForMember(qualifiedName)
// 		);
// 	}
// 
// 	public static RelNode toRel(RelOptCluster cluster, RelOptSchema relOptSchema, Table table, List<String> qualifiedName) {
// 		if (!(table instanceof JdbcTable)) {
// 			throw new UnsupportedOperationException();
// 		}
// 		return toRel(cluster, relOptSchema, (JdbcTable) table, qualifiedName);
// 	}
// }


import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.calcite.adapter.jdbc.JdbcTableUtils;
import org.apache.calcite.plan.Context;
import org.apache.calcite.plan.RelOptCluster;
import org.apache.calcite.plan.RelOptSchema;
import org.apache.calcite.rel.core.TableModify;
import org.apache.calcite.rel.logical.LogicalTableModify;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rex.RexFieldCollation;
import org.apache.calcite.rex.RexInputRef;
import org.apache.calcite.rex.RexNode;
import org.apache.calcite.rex.RexWindowBound;
import org.apache.calcite.schema.Table;
import org.apache.calcite.sql.SqlAggFunction;
import org.apache.calcite.sql.SqlKind;
import org.apache.calcite.sql.SqlWindow;
import org.apache.calcite.sql.parser.SqlParserPos;
import org.apache.calcite.tools.RelBuilder;
import com.google.common.collect.ImmutableList;
				operator,
				expressions,
				partitionKeys,
				orderKeys,
				lowerBound,
				upperBound,
				physical,
				allowPartial,
				nullWhenCountZero
		);
	}

	public RexInputRef appendField(RexNode field) {
		List<RexNode> fields = new ArrayList<>();
		fields.addAll(fields());
		fields.add(field);
		project(fields);
		return field(fields.size() - 1);
	}

	// Table MUST be a JdbcTable (cannot be type-safe since JdbcTable is package-private)
	public JdbcRelBuilder scanJdbc(Table table, List<String> qualifiedName) {
		push(JdbcTableUtils.toRel(cluster, relOptSchema, table, qualifiedName));
		return this;
	}

	public JdbcRelBuilder insertCopying(
			LogicalTableModify original,
			Table table
	) {
// Path: journalled-sql-rewriter/src/main/java/org/apache/calcite/adapter/jdbc/JdbcTableUtils.java
// @SuppressWarnings("WeakerAccess") // Public API
// public class JdbcTableUtils {
// 	private JdbcTableUtils() {
// 		throw new UnsupportedOperationException();
// 	}
// 
// 	private static Object get(Class<?> clazz, Object object, String fieldName) {
// 		try {
// 			Field field = clazz.getDeclaredField(fieldName);
// 			field.setAccessible(true);
// 			return field.get(object);
// 		}
// 		catch (NoSuchFieldException | IllegalAccessException e) {
// 			throw new RuntimeException(e);
// 		}
// 	}
// 
// 	static JdbcTable getJdbcTable(RelNode originalRel) {
// 		return (JdbcTable) get(RelOptTableImpl.class, originalRel.getTable(), "table");
// 	}
// 
// 	static String getCatalogName(JdbcTable table) {
// 		return (String) get(JdbcTable.class, table, "jdbcCatalogName");
// 	}
// 
// 	static String getSchemaName(JdbcTable table) {
// 		return (String) get(JdbcTable.class, table, "jdbcSchemaName");
// 	}
// 
// 	static String getTableName(JdbcTable table) {
// 		// tableName is: [catalog,] [schema,] table
// 		SqlIdentifier identifier = table.tableName();
// 		return identifier.names.get(identifier.names.size() - 1);
// 	}
// 
// 	public static List<String> getQualifiedName(RelOptTable sibling, Table table) {
// 		if (!(table instanceof JdbcTable)) {
// 			throw new UnsupportedOperationException();
// 		}
// 
// 		List<String> name = new ArrayList<>();
// 		if (sibling != null) {
// 			name.addAll(sibling.getQualifiedName());
// 			name.remove(name.size() - 1);
// 		}
// 		name.add(getTableName((JdbcTable) table));
// 		return name;
// 	}
// 
// 	static RelNode toRel(RelOptCluster cluster, RelOptSchema relOptSchema, JdbcTable table, List<String> qualifiedName) {
// 		RelOptTable.ToRelContext toRelContext = new RelOptTable.ToRelContext() {
// 			@Override
// 			public RelOptCluster getCluster() {
// 				return cluster;
// 			}
// 
// 			@Override
// 			public RelRoot expandView(RelDataType rowType, String queryString, List<String> schemaPath, List<String> viewPath) {
// 				throw new UnsupportedOperationException();
// 			}
// 		};
// 
// 		return table.toRel(
// 				toRelContext,
// 				relOptSchema.getTableForMember(qualifiedName)
// 		);
// 	}
// 
// 	public static RelNode toRel(RelOptCluster cluster, RelOptSchema relOptSchema, Table table, List<String> qualifiedName) {
// 		if (!(table instanceof JdbcTable)) {
// 			throw new UnsupportedOperationException();
// 		}
// 		return toRel(cluster, relOptSchema, (JdbcTable) table, qualifiedName);
// 	}
// }


// Path: journalled-sql-rewriter/src/main/java/org/apache/calcite/adapter/jdbc/tools/JdbcRelBuilder.java
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.calcite.adapter.jdbc.JdbcTableUtils;
import org.apache.calcite.plan.Context;
import org.apache.calcite.plan.RelOptCluster;
import org.apache.calcite.plan.RelOptSchema;
import org.apache.calcite.rel.core.TableModify;
import org.apache.calcite.rel.logical.LogicalTableModify;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rex.RexFieldCollation;
import org.apache.calcite.rex.RexInputRef;
import org.apache.calcite.rex.RexNode;
import org.apache.calcite.rex.RexWindowBound;
import org.apache.calcite.schema.Table;
import org.apache.calcite.sql.SqlAggFunction;
import org.apache.calcite.sql.SqlKind;
import org.apache.calcite.sql.SqlWindow;
import org.apache.calcite.sql.parser.SqlParserPos;
import org.apache.calcite.tools.RelBuilder;
import com.google.common.collect.ImmutableList;

				operator,
				expressions,
				partitionKeys,
				orderKeys,
				lowerBound,
				upperBound,
				physical,
				allowPartial,
				nullWhenCountZero
		);
	}

	public RexInputRef appendField(RexNode field) {
		List<RexNode> fields = new ArrayList<>();
		fields.addAll(fields());
		fields.add(field);
		project(fields);
		return field(fields.size() - 1);
	}

	// Table MUST be a JdbcTable (cannot be type-safe since JdbcTable is package-private)
	public JdbcRelBuilder scanJdbc(Table table, List<String> qualifiedName) {
		push(JdbcTableUtils.toRel(cluster, relOptSchema, table, qualifiedName));
		return this;
	}

	public JdbcRelBuilder insertCopying(
			LogicalTableModify original,
			Table table
	) {
		List<String> name = JdbcTableUtils.getQualifiedName(original.getTable(), table);