package org.apache.calcite.adapter.jdbc;

import io.pivotal.beach.calcite.programs.BasicForcedRule;
import org.apache.calcite.adapter.jdbc.tools.JdbcRelBuilder;
import org.apache.calcite.adapter.jdbc.tools.JdbcRelBuilderFactory;
import org.apache.calcite.plan.RelOptTable;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.core.TableModify.Operation;
import org.apache.calcite.rel.logical.LogicalProject;
import org.apache.calcite.rel.logical.LogicalTableModify;

/**
 * Created by tzoloc on 11/25/16.
 */

public class JournalledInsertRule implements BasicForcedRule {
	@Override
	public RelNode apply(RelNode originalRel, JdbcRelBuilderFactory relBuilderFactory) {
		if (!(originalRel instanceof LogicalTableModify)) {
			return null;
		}

		LogicalTableModify tableModify = (LogicalTableModify) originalRel;

		if (!tableModify.getOperation().equals(Operation.INSERT)) {
			return null;
		}

		if (!(tableModify.getInput() instanceof LogicalProject)) {
			return null;
		}

		// Bypass the projection
		tableModify.replaceInput(0, tableModify.getInput(0).getInput(0));

		return tableModify;
	}
}

@@ -39,127 +39,8 @@
 c;%0A%0A
-import io.pivotal.beach.calcite.programs.BasicForcedRule;%0Aimport org.apache.calcite.adapter.jdbc.tools.JdbcRelBuilder;%0A
 impo
@@ -107,52 +107,8 @@
 ry;%0A
-import org.apache.calcite.plan.RelOptTable;%0A
 impo
@@ -254,16 +254,16 @@
 roject;%0A
-
 import o
@@ -313,16 +313,75 @@
 odify;%0A%0A
+import io.pivotal.beach.calcite.programs.BasicForcedRule;%0A%0A
 /**%0A * C

clean imports