本文整理了Java中com.facebook.presto.metadata.Metadata.getTypeManager()
方法的一些代码示例,展示了Metadata.getTypeManager()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Metadata.getTypeManager()
方法的具体详情如下:
包路径:com.facebook.presto.metadata.Metadata
类名称:Metadata
方法名:getTypeManager
暂无
代码示例来源:origin: prestodb/presto
private boolean typesMatchForInsert(Iterable<Type> tableTypes, Iterable<Type> queryTypes)
{
if (Iterables.size(tableTypes) != Iterables.size(queryTypes)) {
return false;
}
Iterator<Type> tableTypesIterator = tableTypes.iterator();
Iterator<Type> queryTypesIterator = queryTypes.iterator();
while (tableTypesIterator.hasNext()) {
Type tableType = tableTypesIterator.next();
Type queryType = queryTypesIterator.next();
if (!metadata.getTypeManager().canCoerce(queryType, tableType)) {
return false;
}
}
return true;
}
代码示例来源:origin: prestodb/presto
public static ExpressionAnalyzer createConstantAnalyzer(Metadata metadata, Session session, List<Expression> parameters, WarningCollector warningCollector)
{
return createWithoutSubqueries(
metadata.getFunctionRegistry(),
metadata.getTypeManager(),
session,
parameters,
EXPRESSION_NOT_CONSTANT,
"Constant expression cannot contain a subquery",
warningCollector,
false);
}
代码示例来源:origin: prestodb/presto
public static ExpressionAnalyzer createConstantAnalyzer(Metadata metadata, Session session, List<Expression> parameters, WarningCollector warningCollector, boolean isDescribe)
{
return createWithoutSubqueries(
metadata.getFunctionRegistry(),
metadata.getTypeManager(),
session,
parameters,
EXPRESSION_NOT_CONSTANT,
"Constant expression cannot contain a subquery",
warningCollector,
isDescribe);
}
代码示例来源:origin: prestodb/presto
private RowExpression toRowExpression(Expression expression, Map<NodeRef<Expression>, Type> types)
{
return SqlToRowExpressionTranslator.translate(expression, SCALAR, types, metadata.getFunctionRegistry(), metadata.getTypeManager(), session, true);
}
代码示例来源:origin: prestodb/presto
private boolean isViewStale(List<ViewDefinition.ViewColumn> columns, Collection<Field> fields)
{
if (columns.size() != fields.size()) {
return true;
}
List<Field> fieldList = ImmutableList.copyOf(fields);
for (int i = 0; i < columns.size(); i++) {
ViewDefinition.ViewColumn column = columns.get(i);
Field field = fieldList.get(i);
if (!column.getName().equalsIgnoreCase(field.getName().orElse(null)) ||
!metadata.getTypeManager().canCoerce(field.getType(), column.getType())) {
return true;
}
}
return false;
}
代码示例来源:origin: prestodb/presto
private boolean isImplicitCoercion(Cast cast)
{
Map<NodeRef<Expression>, Type> expressionTypes = analyzeExpression(cast);
Type actualType = expressionTypes.get(NodeRef.of(cast.getExpression()));
Type expectedType = expressionTypes.get(NodeRef.<Expression>of(cast));
return metadata.getTypeManager().canCoerce(actualType, expectedType);
}
代码示例来源:origin: prestodb/presto
private Map<NodeRef<Expression>, Type> getExpressionTypes(Session session, Expression expression, TypeProvider types)
{
ExpressionAnalyzer expressionAnalyzer = ExpressionAnalyzer.createWithoutSubqueries(
metadata.getFunctionRegistry(),
metadata.getTypeManager(),
session,
types,
emptyList(),
node -> new IllegalStateException("Unexpected node: %s" + node),
WarningCollector.NOOP,
false);
expressionAnalyzer.analyze(expression, Scope.create());
return expressionAnalyzer.getExpressionTypes();
}
代码示例来源:origin: prestodb/presto
private Map<NodeRef<Expression>, Type> getExpressionTypes(Session session, Expression expression, TypeProvider types)
{
ExpressionAnalyzer expressionAnalyzer = ExpressionAnalyzer.createWithoutSubqueries(
metadata.getFunctionRegistry(),
metadata.getTypeManager(),
session,
types,
emptyList(),
node -> new IllegalStateException("Unexpected node: %s" + node),
WarningCollector.NOOP,
false);
expressionAnalyzer.analyze(expression, Scope.create());
return expressionAnalyzer.getExpressionTypes();
}
代码示例来源:origin: prestodb/presto
private Type getType(Expression expression)
{
if (expression instanceof SymbolReference) {
Symbol symbol = Symbol.from(expression);
return requireNonNull(types.get(symbol), () -> format("No type for symbol %s", symbol));
}
ExpressionAnalyzer expressionAnalyzer = ExpressionAnalyzer.createWithoutSubqueries(
metadata.getFunctionRegistry(),
metadata.getTypeManager(),
session,
types,
ImmutableList.of(),
// At this stage, there should be no subqueries in the plan.
node -> new VerifyException("Unexpected subquery"),
WarningCollector.NOOP,
false);
return expressionAnalyzer.analyze(expression, Scope.create());
}
代码示例来源:origin: prestodb/presto
private void verifyTypeSignature(Symbol symbol, TypeSignature expected, TypeSignature actual)
{
// UNKNOWN should be considered as a wildcard type, which matches all the other types
TypeManager typeManager = metadata.getTypeManager();
if (!actual.equals(UNKNOWN.getTypeSignature()) && !typeManager.isTypeOnlyCoercion(typeManager.getType(actual), typeManager.getType(expected))) {
checkArgument(expected.equals(actual), "type of symbol '%s' is expected to be %s, but the actual type is %s", symbol, expected, actual);
}
}
}
代码示例来源:origin: prestodb/presto
private RowExpression toRowExpression(Session session, Expression expression, Map<Symbol, Integer> symbolInput, Map<Integer, Type> inputTypes)
{
// replace qualified names with input references since row expressions do not support these
Expression expressionWithInputReferences = new SymbolToInputRewriter(symbolInput).rewrite(expression);
// determine the type of every expression
Map<NodeRef<Expression>, Type> expressionTypes = getExpressionTypesFromInput(
session,
metadata,
sqlParser,
inputTypes,
expressionWithInputReferences,
emptyList(), /* parameters have already been replaced */
WarningCollector.NOOP);
// convert to row expression
return translate(expressionWithInputReferences, SCALAR, expressionTypes, metadata.getFunctionRegistry(), metadata.getTypeManager(), session, false);
}
代码示例来源:origin: prestodb/presto
public static Object evaluateConstantExpression(Expression expression, Type expectedType, Metadata metadata, Session session, List<Expression> parameters)
{
ExpressionAnalyzer analyzer = createConstantAnalyzer(metadata, session, parameters, WarningCollector.NOOP);
analyzer.analyze(expression, Scope.create());
Type actualType = analyzer.getExpressionTypes().get(NodeRef.of(expression));
if (!metadata.getTypeManager().canCoerce(actualType, expectedType)) {
throw new SemanticException(SemanticErrorCode.TYPE_MISMATCH, expression, format("Cannot cast type %s to %s",
actualType.getTypeSignature(),
expectedType.getTypeSignature()));
}
Map<NodeRef<Expression>, Type> coercions = ImmutableMap.<NodeRef<Expression>, Type>builder()
.putAll(analyzer.getExpressionCoercions())
.put(NodeRef.of(expression), expectedType)
.build();
return evaluateConstantExpression(expression, coercions, analyzer.getTypeOnlyCoercions(), metadata, session, ImmutableSet.of(), parameters);
}
代码示例来源:origin: prestodb/presto
private Map<Symbol, Expression> coerce(Iterable<? extends Expression> expressions, PlanBuilder subPlan, TranslationMap translations)
{
ImmutableMap.Builder<Symbol, Expression> projections = ImmutableMap.builder();
for (Expression expression : expressions) {
Type type = analysis.getType(expression);
Type coercion = analysis.getCoercion(expression);
Symbol symbol = symbolAllocator.newSymbol(expression, firstNonNull(coercion, type));
Expression rewritten = subPlan.rewrite(expression);
if (coercion != null) {
rewritten = new Cast(
rewritten,
coercion.getTypeSignature().toString(),
false,
metadata.getTypeManager().isTypeOnlyCoercion(type, coercion));
}
projections.put(symbol, rewritten);
translations.put(expression, symbol);
}
return projections.build();
}
代码示例来源:origin: prestodb/presto
private RowExpression translateAndOptimize(Expression expression, Map<NodeRef<Expression>, Type> types)
{
return SqlToRowExpressionTranslator.translate(expression, SCALAR, types, metadata.getFunctionRegistry(), metadata.getTypeManager(), TEST_SESSION, true);
}
代码示例来源:origin: prestodb/presto
private RowExpression toRowExpression(Expression projection, Map<NodeRef<Expression>, Type> expressionTypes)
{
return translate(projection, SCALAR, expressionTypes, metadata.getFunctionRegistry(), metadata.getTypeManager(), session, false);
}
代码示例来源:origin: prestodb/presto
private RowExpression rowExpression(String expression, Type type)
{
SymbolToInputRewriter symbolToInputRewriter = new SymbolToInputRewriter(sourceLayout);
Expression inputReferenceExpression = symbolToInputRewriter.rewrite(createExpression(expression, METADATA, TypeProvider.copyOf(symbolTypes)));
ImmutableMap.Builder<Integer, Type> builder = ImmutableMap.builder();
for (int i = 0; i < columnCount; i++) {
builder.put(i, type);
}
Map<Integer, Type> types = builder.build();
Map<NodeRef<Expression>, Type> expressionTypes = getExpressionTypesFromInput(TEST_SESSION, METADATA, SQL_PARSER, types, inputReferenceExpression, emptyList(), WarningCollector.NOOP);
return SqlToRowExpressionTranslator.translate(inputReferenceExpression, SCALAR, expressionTypes, METADATA.getFunctionRegistry(), METADATA.getTypeManager(), TEST_SESSION, true);
}
代码示例来源:origin: prestodb/presto
public static ExpressionAnalyzer create(
Analysis analysis,
Session session,
Metadata metadata,
SqlParser sqlParser,
AccessControl accessControl,
TypeProvider types,
WarningCollector warningCollector)
{
return new ExpressionAnalyzer(
metadata.getFunctionRegistry(),
metadata.getTypeManager(),
node -> new StatementAnalyzer(analysis, metadata, sqlParser, accessControl, session, warningCollector),
session,
types,
analysis.getParameters(),
warningCollector,
analysis.isDescribe());
}
代码示例来源:origin: prestodb/presto
private Map<NodeRef<Expression>, Type> getExpressionTypes(Expression expression)
{
ExpressionAnalyzer expressionAnalyzer = ExpressionAnalyzer.createWithoutSubqueries(
metadata.getFunctionRegistry(),
metadata.getTypeManager(),
TEST_SESSION,
TypeProvider.empty(),
emptyList(),
node -> new IllegalStateException("Unexpected node: %s" + node),
WarningCollector.NOOP,
false);
expressionAnalyzer.analyze(expression, Scope.create());
return expressionAnalyzer.getExpressionTypes();
}
}
代码示例来源:origin: prestodb/presto
Type commonType = metadata.getTypeManager().getCommonSuperType(firstType, secondType).get();
代码示例来源:origin: prestodb/presto
private PlanBuilder handleGroupingOperations(PlanBuilder subPlan, QuerySpecification node, Optional<Symbol> groupIdSymbol, List<Set<FieldId>> groupingSets)
{
if (analysis.getGroupingOperations(node).isEmpty()) {
return subPlan;
}
TranslationMap newTranslations = subPlan.copyTranslations();
Assignments.Builder projections = Assignments.builder();
projections.putIdentities(subPlan.getRoot().getOutputSymbols());
List<Set<Integer>> descriptor = groupingSets.stream()
.map(set -> set.stream()
.map(FieldId::getFieldIndex)
.collect(toImmutableSet()))
.collect(toImmutableList());
for (GroupingOperation groupingOperation : analysis.getGroupingOperations(node)) {
Expression rewritten = GroupingOperationRewriter.rewriteGroupingOperation(groupingOperation, descriptor, analysis.getColumnReferenceFields(), groupIdSymbol);
Type coercion = analysis.getCoercion(groupingOperation);
Symbol symbol = symbolAllocator.newSymbol(rewritten, analysis.getTypeWithCoercions(groupingOperation));
if (coercion != null) {
rewritten = new Cast(
rewritten,
coercion.getTypeSignature().toString(),
false,
metadata.getTypeManager().isTypeOnlyCoercion(analysis.getType(groupingOperation), coercion));
}
projections.put(symbol, rewritten);
newTranslations.put(groupingOperation, symbol);
}
return new PlanBuilder(newTranslations, new ProjectNode(idAllocator.getNextId(), subPlan.getRoot(), projections.build()), analysis.getParameters());
}
内容来源于网络,如有侵权,请联系作者删除!