use of com.wplatform.ddal.value.Value in project jdbc-shards by wplatform.
the class ExpressionColumn method updateAggregate.
@Override
public void updateAggregate(Session session) {
Value now = columnResolver.getValue(column);
Select select = columnResolver.getSelect();
if (select == null) {
throw DbException.get(ErrorCode.MUST_GROUP_BY_COLUMN_1, getSQL());
}
HashMap<Expression, Object> values = select.getCurrentGroup();
if (values == null) {
// this is a different level (the enclosing query)
return;
}
Value v = (Value) values.get(this);
if (v == null) {
values.put(this, now);
} else {
if (!database.areEqual(now, v)) {
throw DbException.get(ErrorCode.MUST_GROUP_BY_COLUMN_1, getSQL());
}
}
}
use of com.wplatform.ddal.value.Value in project jdbc-shards by wplatform.
the class ExpressionColumn method exportParameters.
@Override
public String exportParameters(TableFilter filter, List<Value> container) {
if (getTableFilter() == filter) {
return getSQL();
}
Value value = this.getValue(filter.getSession());
container.add(value);
return "?";
}
use of com.wplatform.ddal.value.Value in project jdbc-shards by wplatform.
the class ExpressionColumn method getValue.
@Override
public Value getValue(Session session) {
Select select = columnResolver.getSelect();
if (select != null) {
HashMap<Expression, Object> values = select.getCurrentGroup();
if (values != null) {
Value v = (Value) values.get(this);
if (v != null) {
return v;
}
}
}
Value value = columnResolver.getValue(column);
if (value == null) {
columnResolver.getValue(column);
throw DbException.get(ErrorCode.MUST_GROUP_BY_COLUMN_1, getSQL());
}
return value;
}
use of com.wplatform.ddal.value.Value in project jdbc-shards by wplatform.
the class AggregateDataHistogram method getValue.
@Override
Value getValue(Database database, int dataType, boolean distinct) {
if (distinct) {
count = 0;
groupDistinct(database, dataType);
}
ValueArray[] values = new ValueArray[distinctValues.size()];
int i = 0;
for (Value dv : distinctValues.keys()) {
AggregateDataHistogram d = distinctValues.get(dv);
values[i] = ValueArray.get(new Value[] { dv, ValueLong.get(d.count) });
i++;
}
final CompareMode compareMode = database.getCompareMode();
Arrays.sort(values, new Comparator<ValueArray>() {
@Override
public int compare(ValueArray v1, ValueArray v2) {
Value a1 = v1.getList()[0];
Value a2 = v2.getList()[0];
return a1.compareTo(a2, compareMode);
}
});
Value v = ValueArray.get(values);
return v.convertTo(dataType);
}
use of com.wplatform.ddal.value.Value in project jdbc-shards by wplatform.
the class AggregateDataSelectivity method getValue.
@Override
Value getValue(Database database, int dataType, boolean distinct) {
if (distinct) {
count = 0;
}
Value v = null;
int s = 0;
if (count == 0) {
s = 0;
} else {
m2 += distinctHashes.size();
m2 = 100 * m2 / count;
s = (int) m2;
s = s <= 0 ? 1 : s > 100 ? 100 : s;
}
v = ValueInt.get(s);
return v.convertTo(dataType);
}
Aggregations