use of io.prestosql.spi.type.TypeSignature in project boostkit-bigdata by kunpengcompute.
the class NdpUdfExpressions method createNdpSplit.
private void createNdpSplit(StringSplit expression, PrestoExpressionInfo prestoExpressionInfo, Map<String, Integer> fieldMap) {
String signatureName = NdpUdfEnum.SPLIT.getSignatureName();
Type strType = NdpUtils.transOlkDataType(expression.str().dataType(), true);
Type regexType = NdpUtils.transOlkDataType(expression.regex().dataType(), true);
Type returnType = NdpUtils.transOlkDataType(expression.dataType(), true);
List<RowExpression> rowArguments = new ArrayList<>();
checkAttributeReference(expression.str(), prestoExpressionInfo, fieldMap, strType, rowArguments);
rowArguments.add(NdpUtils.transArgumentData(expression.regex().toString(), regexType));
Signature signature = new Signature(QualifiedObjectName.valueOfDefaultFunction(NdpUdfEnum.SPLIT.getOperatorName()), FunctionKind.SCALAR, new TypeSignature(returnType.toString()), new TypeSignature(strType.toString()), new TypeSignature(regexType.toString()));
RowExpression resExpression = new CallExpression(signatureName, new BuiltInFunctionHandle(signature), returnType, rowArguments);
prestoExpressionInfo.setReturnType(returnType);
prestoExpressionInfo.setPrestoRowExpression(resExpression);
}
use of io.prestosql.spi.type.TypeSignature in project boostkit-bigdata by kunpengcompute.
the class JsonifyVisitor method visitCall.
@Override
public ObjectNode visitCall(CallExpression call, Void context) {
ObjectNode callRoot = MAPPER.createObjectNode();
// demangle name to get rid of OPERATOR_PREFIX
String callName = call.getDisplayName();
if (callName.startsWith(OPERATOR_PREFIX)) {
callName = callName.substring(OPERATOR_PREFIX.length()).toUpperCase(Locale.ROOT);
}
TypeSignature callSignature = call.getType().getTypeSignature();
DataType returnType = OperatorUtils.toDataType(call.getType());
int typeId = returnType.getId().ordinal();
// Binary operator in rowExpression
if (ARITH_BIN_OPS.contains(callName) || COM_BIN_OPS.contains(callName)) {
callRoot.put("exprType", "BINARY").put("returnType", typeId).put("operator", callName);
if (returnType instanceof Decimal64DataType) {
callRoot.put("precision", ((Decimal64DataType) returnType).getPrecision()).put("scale", ((Decimal64DataType) returnType).getScale());
} else if (returnType instanceof Decimal128DataType) {
callRoot.put("precision", ((Decimal128DataType) returnType).getPrecision()).put("scale", ((Decimal128DataType) returnType).getScale());
}
callRoot.set("left", call.getArguments().get(0).accept(this, context));
callRoot.set("right", call.getArguments().get(1).accept(this, context));
} else if (UNARY_OPS.contains(callName)) {
// Unary operator in rowExpression
callRoot.put("exprType", "UNARY").put("returnType", typeId).put("operator", callName).set("expr", call.getArguments().get(0).accept(this, context));
} else {
// Function call in rowExpression
ArrayNode arguments = MAPPER.createArrayNode();
// Process all arguments of this function call
for (RowExpression argument : call.getArguments()) {
arguments.add(argument.accept(this, context));
}
callRoot.put("exprType", "FUNCTION").put("returnType", typeId).put("function_name", callName).set("arguments", arguments);
if (returnType instanceof VarcharDataType) {
callRoot.put("width", ((VarcharDataType) returnType).getWidth());
} else if (returnType instanceof Decimal64DataType) {
callRoot.put("precision", ((Decimal64DataType) returnType).getPrecision()).put("scale", ((Decimal64DataType) returnType).getScale());
} else if (returnType instanceof Decimal128DataType) {
callRoot.put("precision", ((Decimal128DataType) returnType).getPrecision()).put("scale", ((Decimal128DataType) returnType).getScale());
}
}
return callRoot;
}
use of io.prestosql.spi.type.TypeSignature in project boostkit-bigdata by kunpengcompute.
the class HiveType method getTypeSignature.
private static TypeSignature getTypeSignature(TypeInfo typeInfo) {
switch(typeInfo.getCategory()) {
case PRIMITIVE:
Type primitiveType = getPrimitiveType((PrimitiveTypeInfo) typeInfo);
if (primitiveType == null) {
break;
}
return primitiveType.getTypeSignature();
case MAP:
MapTypeInfo mapTypeInfo = (MapTypeInfo) typeInfo;
TypeSignature keyType = getTypeSignature(mapTypeInfo.getMapKeyTypeInfo());
TypeSignature valueType = getTypeSignature(mapTypeInfo.getMapValueTypeInfo());
return new TypeSignature(StandardTypes.MAP, ImmutableList.of(TypeSignatureParameter.of(keyType), TypeSignatureParameter.of(valueType)));
case LIST:
ListTypeInfo listTypeInfo = (ListTypeInfo) typeInfo;
TypeSignature elementType = getTypeSignature(listTypeInfo.getListElementTypeInfo());
return new TypeSignature(StandardTypes.ARRAY, ImmutableList.of(TypeSignatureParameter.of(elementType)));
case STRUCT:
StructTypeInfo structTypeInfo = (StructTypeInfo) typeInfo;
List<TypeInfo> structFieldTypeInfos = structTypeInfo.getAllStructFieldTypeInfos();
List<String> structFieldNames = structTypeInfo.getAllStructFieldNames();
if (structFieldTypeInfos.size() != structFieldNames.size()) {
throw new PrestoException(HiveErrorCode.HIVE_INVALID_METADATA, format("Invalid Hive struct type: %s", typeInfo));
}
ImmutableList.Builder<TypeSignatureParameter> typeSignatureBuilder = ImmutableList.builder();
for (int i = 0; i < structFieldTypeInfos.size(); i++) {
TypeSignature typeSignature = getTypeSignature(structFieldTypeInfos.get(i));
// Lower case the struct field names.
// Otherwise, Presto will refuse to write to columns whose struct type has field names containing upper case characters.
// Users can't work around this by casting in their queries because Presto parser always lower case types.
// TODO: This is a hack. Presto engine should be able to handle identifiers in a case insensitive way where necessary.
String rowFieldName = structFieldNames.get(i).toLowerCase(Locale.US);
typeSignatureBuilder.add(TypeSignatureParameter.of(new NamedTypeSignature(Optional.of(new RowFieldName(rowFieldName, false)), typeSignature)));
}
return new TypeSignature(StandardTypes.ROW, typeSignatureBuilder.build());
}
throw new PrestoException(NOT_SUPPORTED, format("Unsupported Hive type: %s", typeInfo));
}
use of io.prestosql.spi.type.TypeSignature in project boostkit-bigdata by kunpengcompute.
the class HiveProjectPushdown method tryProjectPushdown.
protected static Optional<TableScanNode> tryProjectPushdown(ProjectNode plan, Map<String, Type> types) {
if (!(plan.getSource() instanceof TableScanNode)) {
return Optional.empty();
}
TableScanNode tableScanNode = (TableScanNode) plan.getSource();
ConnectorTableHandle tableHandle = tableScanNode.getTable().getConnectorHandle();
if (!(tableHandle instanceof HiveTableHandle) || !(((HiveTableHandle) tableHandle).getOffloadExpression().getProjections().isEmpty())) {
return Optional.empty();
}
Map<Symbol, ColumnHandle> assignments = new HashMap<>();
HiveTypeTranslator hiveTypeTranslator = new HiveTypeTranslator();
for (Map.Entry<Symbol, RowExpression> entry : plan.getAssignments().entrySet()) {
String name = entry.getKey().getName();
HiveType hiveType = HiveType.toHiveType(hiveTypeTranslator, entry.getValue().getType());
TypeSignature typeSignature = entry.getValue().getType().getTypeSignature();
HiveColumnHandle columnHandle = new HiveColumnHandle(name, hiveType, typeSignature, DUMMY_OFFLOADED_COLUMN_INDEX, DUMMY_OFFLOADED, Optional.of("projections pushed down " + name));
assignments.put(entry.getKey(), columnHandle);
}
BiMap<VariableReferenceExpression, VariableReferenceExpression> variableToColumnMapping = tableScanNode.getAssignments().entrySet().stream().collect(toImmutableBiMap(entry -> new VariableReferenceExpression(entry.getKey().getName(), types.get(entry.getKey().getName())), entry -> new VariableReferenceExpression(entry.getValue().getColumnName(), types.get(entry.getKey().getName()))));
ImmutableMap.Builder<Symbol, RowExpression> projections = new ImmutableMap.Builder<>();
for (Map.Entry<Symbol, RowExpression> entry : plan.getAssignments().getMap().entrySet()) {
RowExpression expression = replaceExpression(entry.getValue(), variableToColumnMapping);
if (!OmniExpressionChecker.checkExpression(expression)) {
return Optional.empty();
}
projections.put(entry.getKey(), expression);
}
HiveTableHandle hiveTableHandle = (HiveTableHandle) tableHandle;
HiveOffloadExpression offloadExpression = hiveTableHandle.getOffloadExpression().updateProjections(projections.build(), getDataSourceColumns(tableScanNode));
HiveTableHandle newHiveTableHandle = hiveTableHandle.withOffloadExpression(offloadExpression);
TableHandle newTableHandle = new TableHandle(tableScanNode.getTable().getCatalogName(), newHiveTableHandle, tableScanNode.getTable().getTransaction(), tableScanNode.getTable().getLayout());
return Optional.of(new TableScanNode(tableScanNode.getId(), newTableHandle, ImmutableList.copyOf(assignments.keySet()), assignments, tableScanNode.getEnforcedConstraint(), tableScanNode.getPredicate(), tableScanNode.getStrategy(), tableScanNode.getReuseTableScanMappingId(), tableScanNode.getConsumerTableScanNodeCount(), tableScanNode.isForDelete()));
}
use of io.prestosql.spi.type.TypeSignature in project boostkit-bigdata by kunpengcompute.
the class TestHivePageSourceProvider method testModifyDomainGreaterThanOrEqual.
@Test
public void testModifyDomainGreaterThanOrEqual() {
Collection<Object> valueSet = new HashSet<>();
valueSet.add(Long.valueOf(40));
VariableReferenceExpression argument1 = new VariableReferenceExpression("arg_1", BIGINT);
VariableReferenceExpression argument2 = new VariableReferenceExpression("arg_2", BIGINT);
QualifiedObjectName objectName = new QualifiedObjectName("presto", "default", "$operator$greater_than_or_equal");
BuiltInFunctionHandle functionHandle = new BuiltInFunctionHandle(new Signature(objectName, FunctionKind.SCALAR, ImmutableList.of(), ImmutableList.of(), new TypeSignature("boolean"), ImmutableList.of(new TypeSignature("bigint"), new TypeSignature("bigint")), false));
CallExpression filter = new CallExpression("GREATER_THAN_OR_EQUAL", functionHandle, BOOLEAN, ImmutableList.of(argument1, argument2));
Domain domain = Domain.create(ValueSet.copyOf(BIGINT, valueSet), false);
domain = modifyDomain(domain, Optional.of(filter));
assertEquals(domain.getValues().getRanges().getSpan().getHigh().getValueBlock(), Optional.empty());
assertEquals(domain.getValues().getRanges().getSpan().getLow().getValue(), Long.valueOf(40));
}
Aggregations