use of io.prestosql.spi.type.TypeSignature in project hetu-core by openlookeng.
the class AggregationUtils method generateAggregationName.
public static String generateAggregationName(String baseName, TypeSignature outputType, List<TypeSignature> inputTypes) {
StringBuilder sb = new StringBuilder();
sb.append(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, outputType.toString()));
for (TypeSignature inputType : inputTypes) {
sb.append(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, inputType.toString()));
}
sb.append(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, baseName.toLowerCase(ENGLISH)));
return sb.toString();
}
use of io.prestosql.spi.type.TypeSignature in project hetu-core by openlookeng.
the class HiveTypeTranslator method limitedDepthTranslateFromHiveTypeInfo.
private static TypeSignature limitedDepthTranslateFromHiveTypeInfo(TypeInfo typeInfo, int maxDepth) {
int nowDepth = maxDepth - 1;
if (nowDepth <= 0) {
throw new PrestoException(NOT_SUPPORTED, "Hive type nested structure exceed the limit");
}
switch(typeInfo.getCategory()) {
case PRIMITIVE:
Type primitiveType = translateFromHivePrimitiveTypeInfo((PrimitiveTypeInfo) typeInfo);
if (primitiveType == null) {
break;
}
return primitiveType.getTypeSignature();
case MAP:
MapTypeInfo mapTypeInfo = (MapTypeInfo) typeInfo;
TypeSignature keyType = limitedDepthTranslateFromHiveTypeInfo(mapTypeInfo.getMapKeyTypeInfo(), nowDepth);
TypeSignature valueType = limitedDepthTranslateFromHiveTypeInfo(mapTypeInfo.getMapValueTypeInfo(), nowDepth);
return new TypeSignature(StandardTypes.MAP, ImmutableList.of(TypeSignatureParameter.of(keyType), TypeSignatureParameter.of(valueType)));
case LIST:
ListTypeInfo listTypeInfo = (ListTypeInfo) typeInfo;
TypeSignature elementType = limitedDepthTranslateFromHiveTypeInfo(listTypeInfo.getListElementTypeInfo(), nowDepth);
return new TypeSignature(StandardTypes.ARRAY, ImmutableList.of(TypeSignatureParameter.of(elementType)));
}
throw new PrestoException(NOT_SUPPORTED, String.format("Unsupported Hive type: %s", typeInfo));
}
use of io.prestosql.spi.type.TypeSignature in project hetu-core by openlookeng.
the class BuiltInTypeRegistry method addType.
public void addType(String alias, Type type) {
requireNonNull(alias, "alias is null");
requireNonNull(type, "type is null");
Type existingType = types.putIfAbsent(new TypeSignature(alias), type);
checkState(existingType == null || existingType.equals(type), "Alias %s is already mapped to %s", alias, type);
}
use of io.prestosql.spi.type.TypeSignature in project hetu-core by openlookeng.
the class ExternalFunctionsParser method parseExternalFunction.
public static Optional<SqlInvokedFunction> parseExternalFunction(ExternalFunctionInfo externalFunctionInfo, CatalogSchemaName catalogSchemaName, RoutineCharacteristics.Language language) {
Optional<String> functionName = externalFunctionInfo.getFunctionName();
Optional<String> description = externalFunctionInfo.getDescription();
List<String> inputArgs = externalFunctionInfo.getInputArgs();
Optional<String> returnType = externalFunctionInfo.getReturnType();
boolean deterministic = externalFunctionInfo.isDeterministic();
boolean calledOnNullInput = externalFunctionInfo.isCalledOnNullInput();
if (functionName.isPresent() && returnType.isPresent()) {
QualifiedObjectName qualifiedObjectName = new QualifiedObjectName(catalogSchemaName.getCatalogName(), catalogSchemaName.getSchemaName(), functionName.get());
List<Parameter> parameters = inputArgs.stream().map(str -> {
checkState(SUPPORTED_TYPE.contains(str), format("external function do not supported type: %s", str));
if (str.equals(StandardTypes.DECIMAL)) {
return new Parameter(getRandomString((inputArgs.size() / ALPHABET.length() + 1), ALPHABET), parseTypeSignature(str + "(p, s)", ImmutableSet.of("p", "s")));
} else if (str.equals(StandardTypes.CHAR) || str.equals(StandardTypes.VARCHAR)) {
return new Parameter(getRandomString((inputArgs.size() / ALPHABET.length() + 1), ALPHABET), parseTypeSignature(str + "(x)", ImmutableSet.of("x")));
} else {
return new Parameter(getRandomString((inputArgs.size() / ALPHABET.length() + 1), ALPHABET), parseTypeSignature(str));
}
}).collect(toImmutableList());
TypeSignature reType = parseTypeSignature(returnType.get());
String deter = deterministic ? "DETERMINISTIC" : "NOT_DETERMINISTIC";
String nullCallClause = calledOnNullInput ? "CALLED_ON_NULL_INPUT" : "RETURNS_NULL_ON_NULL_INPUT";
RoutineCharacteristics routineCharacteristics = RoutineCharacteristics.builder().setLanguage(new RoutineCharacteristics.Language(language.getLanguage())).setDeterminism(RoutineCharacteristics.Determinism.valueOf(deter)).setNullCallClause(RoutineCharacteristics.NullCallClause.valueOf(nullCallClause)).build();
SqlInvokedFunction sqlInvokedFunction = new SqlInvokedFunction(qualifiedObjectName, parameters, reType, description.orElse(""), routineCharacteristics, EXTERNAL_FUNCTION_BODY, ImmutableMap.of(), Optional.empty());
return Optional.of(sqlInvokedFunction);
}
return Optional.empty();
}
use of io.prestosql.spi.type.TypeSignature in project hetu-core by openlookeng.
the class MongoSession method guessTableFields.
private List<Document> guessTableFields(String schemaName, String tableName) {
MongoDatabase db = client.getDatabase(schemaName);
Document doc = db.getCollection(tableName).find().first();
if (doc == null) {
// no records at the collection
return ImmutableList.of();
}
ImmutableList.Builder<Document> builder = ImmutableList.builder();
for (String key : doc.keySet()) {
Object value = doc.get(key);
Optional<TypeSignature> fieldType = guessFieldType(value);
if (fieldType.isPresent()) {
Document metadata = new Document();
metadata.append(FIELDS_NAME_KEY, key);
metadata.append(FIELDS_TYPE_KEY, fieldType.get().toString());
metadata.append(FIELDS_HIDDEN_KEY, key.equals("_id") && fieldType.get().equals(OBJECT_ID.getTypeSignature()));
builder.add(metadata);
} else {
log.debug("Unable to guess field type from %s : %s", value == null ? "null" : value.getClass().getName(), value);
}
}
return builder.build();
}
Aggregations