[Opt](vectorized) Speed up bucket shuffle join hash compute (#12407)

* [Opt](vectorized) Speed up bucket shuffle join hash compute
This commit is contained in:
HappenLee
2022-09-13 20:19:22 +08:00
committed by GitHub
parent 9a5be4bab5
commit d913ca5731
21 changed files with 274 additions and 98 deletions

View File

@ -40,6 +40,7 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.Year;
@ -495,14 +496,27 @@ public class DateLiteral extends LiteralExpr {
// Date column and Datetime column's hash value is not same.
@Override
public ByteBuffer getHashValue(PrimitiveType type) {
// This hash value should be computed using new String since precision is introduced to datetime.
// But it is hard to keep compatibility. So I don't change this function here.
String value = convertToString(type);
ByteBuffer buffer;
try {
buffer = ByteBuffer.wrap(value.getBytes("UTF-8"));
} catch (Exception e) {
throw new RuntimeException(e);
if (type == PrimitiveType.DATEV2) {
int value = (int) ((year << 9) | (month << 5) | day);
buffer = ByteBuffer.allocate(4);
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.putInt(value);
} else if (type == PrimitiveType.DATETIMEV2) {
long value = (year << 50) | (month << 46) | (day << 41) | (hour << 36)
| (minute << 30) | (second << 24) | microsecond;
buffer = ByteBuffer.allocate(8);
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.putLong(value);
} else {
// This hash value should be computed using new String since precision is introduced to datetime.
// But it is hard to keep compatibility. So I don't change this function here.
String value = convertToString(type);
try {
buffer = ByteBuffer.wrap(value.getBytes("UTF-8"));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return buffer;
}

View File

@ -159,9 +159,6 @@ public class DecimalLiteral extends LiteralExpr {
buffer.putLong(value.longValue());
break;
case DECIMALV2:
case DECIMAL32:
case DECIMAL64:
case DECIMAL128:
buffer = ByteBuffer.allocate(12);
buffer.order(ByteOrder.LITTLE_ENDIAN);
@ -170,6 +167,19 @@ public class DecimalLiteral extends LiteralExpr {
buffer.putLong(integerValue);
buffer.putInt(fracValue);
break;
case DECIMAL32:
buffer = ByteBuffer.allocate(4);
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.putInt(value.unscaledValue().intValue());
break;
case DECIMAL64:
buffer = ByteBuffer.allocate(8);
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.putLong(value.unscaledValue().longValue());
break;
case DECIMAL128:
LargeIntLiteral tmp = new LargeIntLiteral(value.unscaledValue());
return tmp.getHashValue(type);
default:
return super.getHashValue(type);
}

View File

@ -62,6 +62,12 @@ public class LargeIntLiteral extends LiteralExpr {
analysisDone();
}
public LargeIntLiteral(BigInteger v) {
super();
type = Type.LARGEINT;
value = v;
}
public LargeIntLiteral(String value) throws AnalysisException {
super();
BigInteger bigInt;