Skip to content

Commit

Permalink
comit
Browse files Browse the repository at this point in the history
Rate limit · GitHub

Whoa there!

You have triggered an abuse detection mechanism.

Please wait a few minutes before you try again;
in some cases this may take up to an hour.

mengshi.sunmengshi committed Feb 18, 2014
1 parent 30325bb commit 0764aee
Showing 20 changed files with 565 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@
import com.taobao.tddl.common.exception.TddlException;
import com.taobao.tddl.common.utils.GeneralUtil;
import com.taobao.tddl.common.utils.TStringUtil;
import com.taobao.tddl.common.utils.logger.Logger;
import com.taobao.tddl.common.utils.logger.LoggerFactory;
import com.taobao.tddl.executor.codec.CodecFactory;
import com.taobao.tddl.executor.common.ExecutionContext;
import com.taobao.tddl.executor.common.KVPair;
@@ -32,9 +34,6 @@
import com.taobao.tddl.optimizer.core.expression.IOrderBy;
import com.taobao.tddl.optimizer.core.expression.ISelectable;

import com.taobao.tddl.common.utils.logger.Logger;
import com.taobao.tddl.common.utils.logger.LoggerFactory;

/**
* 用于临时表排序,需要依赖bdb
*
@@ -157,9 +156,13 @@ protected ISchematicCursor prepare(IRepository repo, ISchematicCursor cursor, Li
}
for (ColumnMeta column : columns) {
String colName = column.getName();
if (colName.contains(".")) {
String[] sp = TStringUtil.split(colName, ".");
colName = sp[sp.length - 1];
if (colName.contains("_ANDOR_TABLENAME_")) {

int m = colName.indexOf("_ANDOR_TABLENAME_");
colName = colName.substring(m + "_ANDOR_TABLENAME_".length(), colName.length());
// String[] sp = TStringUtil.split(colName,
// "_ANDOR_TABLENAME_");
// colName = sp[sp.length - 1];
}
/**
* 在临时表的时候,来自不同2个表的相同的列,比如 a.id和b.id
@@ -175,11 +178,11 @@ protected ISchematicCursor prepare(IRepository repo, ISchematicCursor cursor, Li
if ("__IDENTITY__".equals(colName)) {
continue;
}
if (colName.contains(".")) {
if (colName.contains("_ANDOR_TABLENAME_")) {
// String[] sp = StringUtil.split(colName, ".");
// colName = sp[sp.length-1];
int m = colName.indexOf(".");
colName = colName.substring(m + 1, colName.length());
int m = colName.indexOf("_ANDOR_TABLENAME_");
colName = colName.substring(m + "_ANDOR_TABLENAME_".length(), colName.length());
}
/**
* 在临时表的时候,来自不同2个表的相同的列,比如 a.id和b.id
@@ -249,7 +252,7 @@ private void buildColumnMeta(ISchematicCursor cursor, List<IOrderBy> orderBys, L
} else {
// 列名与order by not match ,放到value里
ColumnMeta cm2 = new ColumnMeta(cm.getTableName(),
cm.getTableName() + "." + cm.getName(),
cm.getTableName() + "_ANDOR_TABLENAME_" + cm.getName(),
cm.getDataType(),
cm.getAlias(),
cm.isNullable());
@@ -273,7 +276,7 @@ private void buildColumnMeta(ISchematicCursor cursor, List<IOrderBy> orderBys, L
} else {
ISelectable cm = ob.getColumn();
ColumnMeta cm2 = new ColumnMeta(cm.getTableName(),
cm.getTableName() + "." + cm.getColumnName(),
cm.getTableName() + "_ANDOR_TABLENAME_" + cm.getColumnName(),
cm.getDataType(),
cm.getAlias(),
true);
@@ -297,7 +300,7 @@ private boolean findOrderByInKey(List<IOrderBy> orderBys, List<ColumnMeta> colum
if (cm != null && TStringUtil.equals(ExecUtils.getLogicTableName(cm.getTableName()), orderByTable)) {
if (TStringUtil.equals(cm.getName(), iSelectable.getColumnName())) {
ColumnMeta cm2 = new ColumnMeta(cm.getTableName(),
cm.getTableName() + "." + cm.getName(),
cm.getTableName() + "_ANDOR_TABLENAME_" + cm.getName(),
cm.getDataType(),
cm.getAlias(),
cm.isNullable());
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@
import com.taobao.tddl.executor.record.CloneableRecord;
import com.taobao.tddl.executor.rowset.IRowSet;
import com.taobao.tddl.executor.utils.ExecUtils;
import com.taobao.tddl.optimizer.core.datatype.DataTypeUtil;
import com.taobao.tddl.optimizer.core.expression.IBooleanFilter;
import com.taobao.tddl.optimizer.core.expression.IColumn;
import com.taobao.tddl.optimizer.core.expression.IFilter;
@@ -113,7 +114,8 @@ boolean allow(IFilter f, IRowSet iRowSet) throws TddlException {
if (col instanceof ISelectable) {
try {

if (col instanceof IFunction && ((IFunction) col).getFunctionType().equals(FunctionType.Scalar)) {
if (((ISelectable) col).getAlias() == null && col instanceof IFunction
&& ((IFunction) col).getFunctionType().equals(FunctionType.Scalar)) {
column_value = processFunction(iRowSet, col);

} else {
@@ -194,7 +196,8 @@ boolean allow(IFilter f, IRowSet iRowSet) throws TddlException {
return processIn(column_value, bf.getValues());
}

int n = ((Comparable) v).compareTo(column_value);
int n = DataTypeUtil.getTypeOfObject(v).compare(v, column_value);
// int n = ((Comparable) v).compareTo(column_value);

if (n == 0) {
if (op == OPERATION.EQ || op == OPERATION.GT_EQ || op == OPERATION.LT_EQ) {
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ public void serverMap(Object[] args) throws FunctionException {
if (total == null) {
total = type.convertFrom(o);
} else {
total = type.getCalculator().doAdd(total, o);
total = type.getCalculator().add(total, o);
}
}
}
@@ -44,7 +44,7 @@ public void serverReduce(Object[] args) throws FunctionException {
if (total == null) {
total = type.convertFrom(o);
} else {
total = type.getCalculator().doAdd(total, o);
total = type.getCalculator().add(total, o);
}
}

@@ -69,9 +69,9 @@ private String bulidAvgSql(IFunction func) {
public Object getResult() {
DataType type = this.getReturnType();
if (total == null) {
return type.getCalculator().doDivide(0L, count);
return type.getCalculator().divide(0L, count);
} else {
return type.getCalculator().doDivide(total, count);
return type.getCalculator().divide(total, count);
}
}

Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ private void doSum(Object[] args) {
o = type.convertFrom(o);
result = o;
} else {
result = type.getCalculator().doAdd(result, o);
result = type.getCalculator().add(result, o);
}

}
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ public class Add extends ScalarFunction {

private Object computeInner(Object[] args) {
DataType type = this.getReturnType();
return type.getCalculator().doAdd(args[0], args[1]);
return type.getCalculator().add(args[0], args[1]);
}

@Override
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ public void compute(Object[] args) {

private Object computeInner(Object[] args) {
DataType type = this.getReturnType();
return type.getCalculator().doBitAnd(args[0], args[1]);
return type.getCalculator().bitAnd(args[0], args[1]);
}

@Override
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ public void compute(Object[] args) {

private Object computeInner(Object[] args) {
DataType type = this.getReturnType();
return type.getCalculator().doBitOr(args[0], args[1]);
return type.getCalculator().bitOr(args[0], args[1]);
}

@Override
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ public void compute(Object[] args) {

private Object computeInner(Object[] args) {
DataType type = this.getReturnType();
return type.getCalculator().doBitXor(args[0], args[1]);
return type.getCalculator().bitXor(args[0], args[1]);
}

@Override
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ public void compute(Object[] args) {

private Object computeInner(Object[] args) {
DataType type = this.getReturnType();
return type.getCalculator().doDivide(args[0], args[1]);
return type.getCalculator().divide(args[0], args[1]);
}

@Override
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ public void compute(Object[] args) {

private Object computeInner(Object[] args) {
DataType type = this.getReturnType();
return type.getCalculator().doDivide(args[0], args[1]);
return type.getCalculator().divide(args[0], args[1]);
}

@Override
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ public DataType getReturnType() {
private Object computeInner(Object[] args) {
DataType type = getReturnType();
// -min(id) = min(id) * -1
return type.getCalculator().doMultiply(args[0], -1);
return type.getCalculator().multiply(args[0], -1);
}

}
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ public class Mod extends ScalarFunction {

private Object computeInner(Object[] args) {
DataType type = this.getReturnType();
return type.getCalculator().doMod(args[0], args[1]);
return type.getCalculator().mod(args[0], args[1]);

}

Original file line number Diff line number Diff line change
@@ -31,6 +31,6 @@ public DataType getReturnType() {

private Object computeInner(Object[] args) {
DataType type = this.getReturnType();
return type.getCalculator().doMultiply(args[0], args[1]);
return type.getCalculator().multiply(args[0], args[1]);
}
}
Original file line number Diff line number Diff line change
@@ -31,6 +31,6 @@ public DataType getReturnType() {

private Object computeInner(Object[] args) {
DataType type = this.getReturnType();
return type.getCalculator().doSub(args[0], args[1]);
return type.getCalculator().sub(args[0], args[1]);
}
}
Original file line number Diff line number Diff line change
@@ -171,7 +171,11 @@ public String toString() {

for (ColumnMeta cm : this.getParentCursorMeta().getColumns()) {
int index = this.getParentCursorMeta().getIndex(cm.getTableName(), cm.getName());
sb.append(cm.getName() + ":" + this.getValues().get(index) + " ");

if (index > this.getValues().size()) {
System.out.println("11");
}
sb.append(cm.getName() + ":" + this.getString(index) + " ");
}
return sb.toString();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package com.taobao.tddl.optimizer.core.datatype;

public abstract class AbstractCalculator implements Calculator {

public abstract Object doAdd(Object v1, Object v2);

public abstract Object doSub(Object v1, Object v2);

public abstract Object doMultiply(Object v1, Object v2);

public abstract Object doDivide(Object v1, Object v2);

public abstract Object doMod(Object v1, Object v2);

public abstract Object doAnd(Object v1, Object v2);

public abstract Object doOr(Object v1, Object v2);

public abstract Object doXor(Object v1, Object v2);

public abstract Object doNot(Object v1);

public abstract Object doBitAnd(Object v1, Object v2);

public abstract Object doBitOr(Object v1, Object v2);

public abstract Object doBitXor(Object v1, Object v2);

public abstract Object doBitNot(Object v1);

@Override
public Object add(Object v1, Object v2) {
if (v1 == null || v2 == null) return null;

return this.doAdd(v1, v2);
}

@Override
public Object sub(Object v1, Object v2) {
if (v1 == null || v2 == null) return null;

return this.doSub(v1, v2);
}

@Override
public Object multiply(Object v1, Object v2) {
if (v1 == null || v2 == null) return null;

return this.doMultiply(v1, v2);
}

@Override
public Object divide(Object v1, Object v2) {
if (v1 == null || v2 == null) return null;

return this.doDivide(v1, v2);
}

@Override
public Object mod(Object v1, Object v2) {
if (v1 == null || v2 == null) return null;

return this.doMod(v1, v2);
}

@Override
public Object and(Object v1, Object v2) {
if (v1 == null || v2 == null) return null;

return this.doAnd(v1, v2);
}

@Override
public Object or(Object v1, Object v2) {
if (v1 == null || v2 == null) return null;

return this.doOr(v1, v2);
}

@Override
public Object xor(Object v1, Object v2) {
if (v1 == null || v2 == null) return null;

return this.doXor(v1, v2);
}

@Override
public Object not(Object v1) {
if (v1 == null) return null;

return this.doNot(v1);
}

@Override
public Object bitAnd(Object v1, Object v2) {
if (v1 == null || v2 == null) return null;

return this.doBitAnd(v1, v2);
}

@Override
public Object bitOr(Object v1, Object v2) {
if (v1 == null || v2 == null) return null;

return this.doBitOr(v1, v2);
}

@Override
public Object bitXor(Object v1, Object v2) {
if (v1 == null || v2 == null) return null;

return this.doBitXor(v1, v2);
}

@Override
public Object bitNot(Object v1) {
if (v1 == null) return null;

return this.doBitNot(v1);
}

}
Rate limit · GitHub

Whoa there!

You have triggered an abuse detection mechanism.

Please wait a few minutes before you try again;
in some cases this may take up to an hour.

0 comments on commit 0764aee

Please sign in to comment.