提交 2f6921ae authored 作者: Owner's avatar Owner

Removed debug statements

上级 920722fc
......@@ -1094,29 +1094,11 @@ public class Parser {
}
return command;
}
/*
* TODO finish writing this MergeUsing
MERGE INTO targetTableName [[AS] t_alias] USING table_reference [[AS} s_alias] ON ( condition ,...)
WHEN MATCHED THEN
[UPDATE SET column1 = value1 [, column2 = value2 ... WHERE ...]
[DELETE WHERE ...]
WHEN NOT MATCHED THEN
INSERT (column1 [, column2 ...]) VALUES (value1 [, value2 ...]);
table_reference ::= table | view | ( sub-query )
The current implementation (for comparison) uses this syntax:
MERGE INTO tablename [(columnName1,...)]
[KEY (keyColumnName1,...)]
[ VALUES (expression1,...) | SELECT ...]
*/
/* TODO: Finish coding parseMergeUsing */
private MergeUsing parseMergeUsing(Merge oldCommand, int start) {
/* TODO: not sure why schema name is reset to null */
if(schemaName==null){
schemaName = session.getCurrentSchemaName();
System.out.println("schemaName="+schemaName);
}
Schema schema = getSchema();
......@@ -1125,29 +1107,25 @@ public class Parser {
currentPrepared = command;
if (readIf("(")) {
System.out.println("pre select schema="+getSchema()+",schemaName="+schemaName);
/* a select query is supplied */
if (isSelect()) {
command.setQuery(parseSelect());
System.out.println("post select schema="+getSchema()+",schemaName="+schemaName);
schemaName = savedSchemaName;
System.out.println("post2 select schema="+getSchema()+",schemaName="+schemaName);
read(")");
}
command.setQueryAlias(readFromAlias(null, Arrays.asList("ON")));
String[] querySQLOutput = new String[]{null};
List<Column> columnTemplateList = createQueryColumnTemplateList(null, command.getQuery(), querySQLOutput);
System.out.println("pre:alias="+command.getQueryAlias()+",sql="+querySQLOutput[0]+",ctlist="+columnTemplateList+",schema="+getSchema()+",schemaName="+schemaName);
TableView temporarySourceTableView = createTemporarySessionView(command.getQueryAlias(), querySQLOutput[0], columnTemplateList, false, false);
command.setTemporaryTableView(temporarySourceTableView);
System.out.println("sourceTableFilter with tableOrView="+temporarySourceTableView);
System.out.println("sourceTableFilter rightsChecked="+rightsChecked);
TableFilter sourceTableFilter = new TableFilter(session, temporarySourceTableView, command.getQueryAlias(), rightsChecked,
(Select) command.getQuery(), 0, null);
command.setSourceTableFilter(sourceTableFilter);
}
else{
/* Its a table name, simulate a query by building a select query for the table */
List<String> excludeIdentifiers = Arrays.asList("ON");
TableFilter sourceTableFilter = readSimpleTableFilterWithAliasExcludes(0,excludeIdentifiers);
command.setSourceTableFilter(sourceTableFilter);
......@@ -1157,9 +1135,7 @@ public class Parser {
if(sourceTableFilter.getTableAlias()!=null){
buff.append(" AS "+sourceTableFilter.getTableAlias());
}
//ArrayList<Value> paramValues = New.arrayList();
Prepared preparedQuery = prepare(session, buff.toString(), null/*paramValues*/);
System.out.println("class="+preparedQuery.getClass());
command.setQuery((Select)preparedQuery);
}
......@@ -1197,14 +1173,6 @@ public class Parser {
}
}
if(command.getQueryAlias()!=null){
if(schema==null){
System.out.println("Why oh why is the schema null???");
System.out.println("schemaName="+schemaName);
throw DbException.getUnsupportedException("unexpected null schema");
}
}
setSQL(command, "MERGE", start);
return command;
}
......@@ -5198,7 +5166,6 @@ public class Parser {
withQuery.prepare();
querySQLOutput[0] = StringUtils.cache(withQuery.getPlanSQL());
ArrayList<Expression> withExpressions = withQuery.getExpressions();
System.out.println("withExpressions="+withExpressions);
for (int i = 0; i < withExpressions.size(); ++i) {
Expression columnExp = withExpressions.get(i);
// use the passed in column name if supplied, otherwise use alias (if used) otherwise use column name
......@@ -5225,7 +5192,6 @@ public class Parser {
// No easy way to determine if this is a recursive query up front, so we just compile
// it twice - once without the flag set, and if we didn't see a recursive term,
// then we just compile it again.
System.out.println("createTemporarySessionView="+tempViewName);
TableView view = new TableView(schema, id, tempViewName, querySQL,
parameters, columnTemplateList.toArray(new Column[0]), session,
allowRecursiveQueryDetection/* recursive */, false);
......
......@@ -56,7 +56,6 @@ public class MergeUsing extends Merge {
// bring across only the already parsed data from Merge...
this.targetTable = merge.targetTable;
this.targetTableFilter = merge.targetTableFilter;
}
......@@ -64,8 +63,6 @@ public class MergeUsing extends Merge {
public int update() {
sourceKeysRemembered.clear();
System.out.println("update using:"+temporarySourceTableView);
if(targetTableFilter!=null){
targetTableFilter.startQuery(session);
targetTableFilter.reset();
......@@ -89,11 +86,9 @@ public class MergeUsing extends Merge {
countInputRows++;
Value[] sourceRowValues = rows.currentRow();
Row sourceRow = new RowImpl(sourceRowValues,0);
System.out.println(("currentRowValues="+Arrays.toString(sourceRowValues)));
Row newTargetRow = targetTable.getTemplateRow();
ArrayList<Value> sourceKeyValuesList = new ArrayList<Value>();
setCurrentRowNumber(countInputRows);
System.out.println("columns="+Arrays.toString(columns));
// isolate the source row key columns values
for (int j = 0; j < sourceKeys.length; j++) {
......@@ -168,29 +163,22 @@ public class MergeUsing extends Merge {
// try and perform an update
int rowUpdateCount = 0;
System.out.println("onConditions="+onCondition.toString());
if(updateCommand!=null){
System.out.println("updatePlanSQL="+updateCommand.getPlanSQL());
rowUpdateCount += updateCommand.update();
System.out.println("update.count="+rowUpdateCount);
}
if(deleteCommand!=null){
System.out.println("deleteCommand="+deleteCommand.getPlanSQL());
rowUpdateCount += deleteCommand.update();
System.out.println("delete.count="+rowUpdateCount);
}
// if either updates do nothing, try an insert
if (rowUpdateCount == 0) {
rowUpdateCount+=addRowByCommandInsert(session,newTargetRow);
//addRowByAPIInsert(session,newTargetRow);
} else if (rowUpdateCount != 1) {
throw DbException.get(ErrorCode.DUPLICATE_KEY_1, "Duplicate key updated "+rowUpdateCount+" rows at once, only 1 expected:"+targetTable.getSQL());
}
countUpdatedRows+=rowUpdateCount;
}
private void configPreparedParameters(Row newTargetRow, Prepared updatePrepared) {
ArrayList<Parameter> k = updatePrepared.getParameters();
// set each parameter in the updatePrepared with the real value from the source column
......@@ -216,56 +204,13 @@ public class MergeUsing extends Merge {
private int addRowByCommandInsert(Session session, Row newTargetRow) {
int localCount = 0;
if(insertCommand!=null){
System.out.println("insertPlanSQL="+insertCommand.getPlanSQL());
localCount += insertCommand.update();
}
System.out.println("insert.count="+localCount);
return localCount;
}
private int addRowByAPIInsert(Session session, Row newTargetRow) {
System.out.println("addRowByInsert=(hashcode)"+newTargetRow.hashCode());
try {
targetTable.validateConvertUpdateSequence(session, newTargetRow);
boolean done = targetTable.fireBeforeRow(session, null, newTargetRow);
if (!done) {
targetTable.lock(session, true, false);
targetTable.addRow(session, newTargetRow);
session.log(targetTable, UndoLogRecord.INSERT, newTargetRow);
targetTable.fireAfterRow(session, null, newTargetRow, false);
return 1;
}
return 0;
} catch (DbException e) {
if (e.getErrorCode() == ErrorCode.DUPLICATE_KEY_1) {
// possibly a concurrent merge or insert
Index index = (Index) e.getSource();
if (index != null) {
// verify the index columns match the key
Column[] indexColumns = index.getColumns();
boolean indexMatchesKeys = true;
if (indexColumns.length <= keys.length) {
for (int i = 0; i < indexColumns.length; i++) {
if (indexColumns[i] != keys[i]) {
indexMatchesKeys = false;
break;
}
}
}
if (indexMatchesKeys) {
throw DbException.get(ErrorCode.CONCURRENT_UPDATE_1, targetTable.getName());
}
}
}
throw e;
}
}
@Override
public String getPlanSQL() {
System.out.println("getPlanSQL");
StatementBuilder buff = new StatementBuilder("MERGE INTO ");
buff.append(targetTable.getSQL()).append('(');
for (Column c : columns) {
......@@ -307,55 +252,9 @@ public class MergeUsing extends Merge {
}
return buff.toString();
}
/*
@Override
public void prepare() {
if (condition != null) {
condition.mapColumns(tableFilter, 0);
condition = condition.optimize(session);
condition.createIndexConditions(session, tableFilter);
}
for (int i = 0, size = columns.size(); i < size; i++) {
Column c = columns.get(i);
Expression e = expressionMap.get(c);
e.mapColumns(tableFilter, 0);
expressionMap.put(c, e.optimize(session));
}
TableFilter[] filters = new TableFilter[] { tableFilter };
PlanItem item = tableFilter.getBestPlanItem(session, filters, 0,
ExpressionVisitor.allColumnsForTableFilters(filters));
tableFilter.setPlanItem(item);
tableFilter.prepare();
}
*/
/*
MERGE INTO targetTableName [[AS] t_alias] USING table_reference [[AS} s_alias] ON ( condition ,...)
WHEN MATCHED THEN
[UPDATE SET column1 = value1 [, column2 = value2 ... WHERE ...]
[DELETE WHERE ...]
WHEN NOT MATCHED THEN
INSERT (column1 [, column2 ...]) VALUES (value1 [, value2 ...]);
table_reference ::= table | view | ( sub-query )
The current implementation (for comparison) uses this syntax:
MERGE INTO tablename [(columnName1,...)]
[KEY (keyColumnName1,...)]
[ VALUES (expression1,...) | SELECT ...]
*/
@Override
public void prepare() {
System.out.println("prepare:targetTableFilterAlias="+targetTableFilter.getTableAlias());
System.out.println("prepare:sourceTableFilterAlias="+sourceTableFilter.getTableAlias());
System.out.println("prepare:onConditions="+onCondition);
//TableFilter[] filters = new TableFilter[] { sourceTableFilter, targetTableFilter };
System.out.println("onCondition="+onCondition+":op="+onCondition.getClass().getSimpleName());
onCondition.addFilterConditions(sourceTableFilter, true);
onCondition.addFilterConditions(targetTableFilter, true);
onCondition.mapColumns(sourceTableFilter, 2);
......@@ -365,24 +264,23 @@ public class MergeUsing extends Merge {
if (keys == null) {
HashSet<Column> targetColumns = buildColumnListFromOnCondition(targetTableFilter);
keys = targetColumns.toArray(new Column[0]);
System.out.println("keys.length="+keys.length);
}
if(keys.length==0){
throw DbException.get(ErrorCode.COLUMN_NOT_FOUND_1,"No references to target columns found in ON clause:"+targetTableFilter.toString());
throw DbException.get(ErrorCode.COLUMN_NOT_FOUND_1,
"No references to target columns found in ON clause:"+targetTableFilter.toString());
}
if (sourceKeys == null) {
HashSet<Column> sourceColumns = buildColumnListFromOnCondition(sourceTableFilter);
sourceKeys = sourceColumns.toArray(new Column[0]);
System.out.println("sourceKeys.length="+sourceKeys.length);
}
if(sourceKeys.length==0){
throw DbException.get(ErrorCode.COLUMN_NOT_FOUND_1,"No references to source columns found in ON clause:"+sourceTableFilter.toString());
throw DbException.get(ErrorCode.COLUMN_NOT_FOUND_1,
"No references to source columns found in ON clause:"+sourceTableFilter.toString());
}
// only do the optimise now - before we have already gathered the unoptimized column data
// only do the optimize now - before we have already gathered the unoptimized column data
onCondition = onCondition.optimize(session);
onCondition.createIndexConditions(session, sourceTableFilter);
//optional
onCondition.createIndexConditions(session, targetTableFilter);
if (columns == null) {
......@@ -411,13 +309,6 @@ public class MergeUsing extends Merge {
throw DbException.get(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH);
}
}
// if (keys == null) {
// Index idx = targetTable.getPrimaryKey();
// if (idx == null) {
// throw DbException.get(ErrorCode.CONSTRAINT_NOT_FOUND_1, "PRIMARY KEY");
// }
// keys = idx.getColumns();
// }
String sql = buildPreparedSQL();
update = session.prepare(sql);
......@@ -437,23 +328,18 @@ public class MergeUsing extends Merge {
insertCommand.setSourceTableFilter(sourceTableFilter);
insertCommand.prepare();
}
}
private HashSet<Column> buildColumnListFromOnCondition(TableFilter anyTableFilter) {
HashSet<Column> filteredColumns = new HashSet<Column>();
HashSet<Column> columns = new HashSet<Column>();
ExpressionVisitor visitor = ExpressionVisitor.getColumnsVisitor(columns);
onCondition.isEverything(visitor);
for(Column c: columns){
System.out.println("C="+c);
if(c!=null && c.getTable()==anyTableFilter.getTable()){
filteredColumns.add(c);
}
}
System.out.println("columnsVisitedForTable"+anyTableFilter.getTable()+"="+filteredColumns);
return filteredColumns;
}
......@@ -491,44 +377,6 @@ public class MergeUsing extends Merge {
String sql = buff.toString();
return sql;
}
private String buildPreparedSQLForMergeUsing() {
StatementBuilder buff = new StatementBuilder("MERGE INTO ");
buff.append(targetTable.getSQL());
if(targetTableFilter.getTableAlias()!=null){
buff.append(" AS "+targetTableFilter.getTableAlias()+"\n");
}
buff.append("USING \n");
buff.append(temporarySourceTableView.getSQL());
buff.append("\n");
if(sourceTableFilter.getTableAlias()!=null){
buff.append(" AS "+sourceTableFilter.getTableAlias()+"\n");
}
buff.append("ON (");
buff.append(onCondition.getSQL());
buff.append(" )");
if(updateCommand!=null || deleteCommand!=null){
buff.append("\nWHEN MATCHED\n");
if(updateCommand!=null){
buff.append(updateCommand.getPlanSQL());
}
if(deleteCommand!=null){
buff.append(deleteCommand.getPlanSQL());
}
}
if(insertCommand!=null){
buff.append("\nWHEN NOT MATCHED\n");
if(insertCommand!=null){
buff.append(insertCommand.getPlanSQL());
}
}
// buff.resetCount();
// for (Column c : keys) {
// buff.appendExceptFirst(" AND ");
// buff.append(c.getSQL()).append("=?");
// }
String sql = buff.toString();
return sql;
}
public void setSourceTableFilter(TableFilter sourceTableFilter) {
this.sourceTableFilter = sourceTableFilter;
......
......@@ -492,10 +492,8 @@ public class Comparison extends Condition {
@Override
public void mapColumns(ColumnResolver resolver, int level) {
System.out.println("Checking left:"+left+" against "+resolver);
left.mapColumns(resolver, level);
if (right != null) {
System.out.println("Checking right:"+right+" against "+resolver);
right.mapColumns(resolver, level);
}
}
......
......@@ -117,11 +117,9 @@ public class ExpressionColumn extends Expression {
queryLevel = level;
column = col;
this.columnResolver = resolver;
System.out.println("mapColumn: Setting resolver:"+col+"@"+System.identityHashCode(col)+" by resolver "+resolver+"-"+resolver.getClass());
} else if (queryLevel == level && this.columnResolver != resolver) {
if (resolver instanceof SelectListColumnResolver) {
// ignore - already mapped, that's ok
System.out.println("mapColumn: Already mapped:"+col+"@"+System.identityHashCode(col)+" by resolver "+resolver+"-"+resolver.getClass());
} else {
throw DbException.get(ErrorCode.AMBIGUOUS_COLUMN_NAME_1, columnName);
}
......
......@@ -85,9 +85,6 @@ public abstract class Table extends SchemaObjectBase {
public Table(Schema schema, int id, String name, boolean persistIndexes,
boolean persistData) {
System.out.println("newTable:schema="+schema);
System.out.println("newTable:name="+name);
System.out.println("newTable:schema="+schema+",database="+schema.getDatabase());
columnMap = schema.getDatabase().newStringMap();
initSchemaObjectBase(schema, id, name, Trace.TABLE);
this.persistIndexes = persistIndexes;
......
......@@ -567,8 +567,6 @@ public class TableFilter implements ColumnResolver {
private void checkTimeout() {
session.checkCanceled();
// System.out.println(this.alias+ " " + table.getName() + ": " +
// scanCount);
}
/**
......
......@@ -191,7 +191,6 @@ public class TestMergeUsing extends TestBase {
while (rs.next()) {
rowCount++;
diffBuffer.append("|");
System.out.println("rs.getMetaData().getColumnCount()="+rs.getMetaData().getColumnCount());
for(int ndx = 1; ndx <= rs.getMetaData().getColumnCount(); ndx++){
diffBuffer.append(rs.getObject(ndx));
diffBuffer.append("|\n");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论