@Override protected Void visitSampledRelation(SampledRelation node, Integer indent) { process(node.getRelation(), indent); builder.append(" TABLESAMPLE ") .append(node.getType()) .append(" (") .append(node.getSamplePercentage()) .append(')'); return null; }
@Override protected Void visitSampledRelation(SampledRelation node, Integer indentLevel) { print(indentLevel, "TABLESAMPLE[" + node.getType() + " (" + node.getSamplePercentage() + ")]"); super.visitSampledRelation(node, indentLevel + 1); return null; }
@Override protected R visitSampledRelation(SampledRelation node, C context) { process(node.getRelation(), context); process(node.getSamplePercentage(), context); return null; }
@Override protected Void visitSampledRelation(SampledRelation node, Integer indent) { process(node.getRelation(), indent); builder.append(" TABLESAMPLE ") .append(node.getType()) .append(" (") .append(node.getSamplePercentage()) .append(')'); if (node.getColumnsToStratifyOn().isPresent()) { builder.append(" STRATIFY ON ") .append(" (") .append(Joiner.on(",").join(node.getColumnsToStratifyOn().get())); builder.append(')'); } return null; }
@Override protected RelationPlan visitSampledRelation(SampledRelation node, Void context) { RelationPlan subPlan = process(node.getRelation(), context); double ratio = analysis.getSampleRatio(node); PlanNode planNode = new SampleNode(idAllocator.getNextId(), subPlan.getRoot(), ratio, SampleNode.Type.fromType(node.getType())); return new RelationPlan(planNode, analysis.getScope(node), subPlan.getFieldMappings()); }
@Override protected Void visitSampledRelation(SampledRelation node, Integer indentLevel) { String stratifyOn = ""; if (node.getColumnsToStratifyOn().isPresent()) { stratifyOn = " STRATIFY ON (" + node.getColumnsToStratifyOn().get().toString() + ")"; } print(indentLevel, "TABLESAMPLE[" + node.getType() + " (" + node.getSamplePercentage() + ")" + stratifyOn + "]"); super.visitSampledRelation(node, indentLevel + 1); return null; }
@Override protected R visitSampledRelation(SampledRelation node, C context) { process(node.getRelation(), context); process(node.getSamplePercentage(), context); if (node.getColumnsToStratifyOn().isPresent()) { for (Expression expression : node.getColumnsToStratifyOn().get()) { process(expression, context); } } return null; }
@Override public Node visitSampledRelation(SqlBaseParser.SampledRelationContext context) { Relation child = (Relation) visit(context.aliasedRelation()); if (context.TABLESAMPLE() == null) { return child; } return new SampledRelation( getLocation(context), child, getSamplingMethod((Token) context.sampleType().getChild(0).getPayload()), (Expression) visit(context.percentage)); }
@Override protected Void visitSampledRelation(SampledRelation node, Integer indent) { process(node.getRelation(), indent); builder.append(" TABLESAMPLE ") .append(node.getType()) .append(" (") .append(node.getSamplePercentage()) .append(')'); if (node.getColumnsToStratifyOn().isPresent()) { builder.append(" STRATIFY ON ") .append(" (") .append(Joiner.on(",").join(node.getColumnsToStratifyOn().get())); builder.append(')'); } return null; }
@Override protected Scope visitSampledRelation(SampledRelation relation, Optional<Scope> scope) if (!SymbolsExtractor.extractNames(relation.getSamplePercentage(), analysis.getColumnReferences()).isEmpty()) { throw new SemanticException(NON_NUMERIC_SAMPLE_PERCENTAGE, relation.getSamplePercentage(), "Sample percentage cannot contain column references"); sqlParser, TypeProvider.empty(), relation.getSamplePercentage(), analysis.getParameters(), WarningCollector.NOOP, analysis.isDescribe()); ExpressionInterpreter samplePercentageEval = expressionOptimizer(relation.getSamplePercentage(), metadata, session, expressionTypes); throw new SemanticException(NON_NUMERIC_SAMPLE_PERCENTAGE, relation.getSamplePercentage(), "Sample percentage cannot contain column references"); }); throw new SemanticException(NON_NUMERIC_SAMPLE_PERCENTAGE, relation.getSamplePercentage(), "Sample percentage should evaluate to a numeric expression"); throw new SemanticException(SemanticErrorCode.SAMPLE_PERCENTAGE_OUT_OF_RANGE, relation.getSamplePercentage(), "Sample percentage must be greater than or equal to 0"); throw new SemanticException(SemanticErrorCode.SAMPLE_PERCENTAGE_OUT_OF_RANGE, relation.getSamplePercentage(), "Sample percentage must be less than or equal to 100"); Scope relationScope = process(relation.getRelation(), scope); return createAndAssignScope(relation, scope, relationScope.getRelationType());
@Override protected Void visitSampledRelation(SampledRelation node, Integer indentLevel) { print(indentLevel, "TABLESAMPLE[" + node.getType() + " (" + node.getSamplePercentage() + ")]"); super.visitSampledRelation(node, indentLevel + 1); return null; }
@Override public Node visitSampledRelation(SqlBaseParser.SampledRelationContext context) { Relation child = (Relation) visit(context.aliasedRelation()); if (context.TABLESAMPLE() == null) { return child; } Optional<List<Expression>> stratifyOn = Optional.empty(); if (context.STRATIFY() != null) { stratifyOn = Optional.of(visit(context.stratify, Expression.class)); } return new SampledRelation( getLocation(context), child, getSamplingMethod((Token) context.sampleType().getChild(0).getPayload()), (Expression) visit(context.percentage), context.RESCALED() != null, stratifyOn); }
@Override protected RelationType visitSampledRelation(SampledRelation relation, AnalysisContext context) if (relation.getColumnsToStratifyOn().isPresent()) { throw new SemanticException(NOT_SUPPORTED, relation, "STRATIFY ON is not yet implemented"); if (!DependencyExtractor.extractNames(relation.getSamplePercentage(), analysis.getColumnReferences()).isEmpty()) { throw new SemanticException(NON_NUMERIC_SAMPLE_PERCENTAGE, relation.getSamplePercentage(), "Sample percentage cannot contain column references"); IdentityHashMap<Expression, Type> expressionTypes = getExpressionTypes(session, metadata, sqlParser, ImmutableMap.<Symbol, Type>of(), relation.getSamplePercentage()); ExpressionInterpreter samplePercentageEval = expressionOptimizer(relation.getSamplePercentage(), metadata, session, expressionTypes); throw new SemanticException(NON_NUMERIC_SAMPLE_PERCENTAGE, relation.getSamplePercentage(), "Sample percentage cannot contain column references"); }); throw new SemanticException(NON_NUMERIC_SAMPLE_PERCENTAGE, relation.getSamplePercentage(), "Sample percentage should evaluate to a numeric expression"); throw new SemanticException(SemanticErrorCode.SAMPLE_PERCENTAGE_OUT_OF_RANGE, relation.getSamplePercentage(), "Sample percentage must be greater than or equal to 0"); if ((samplePercentageValue > 100.0) && ((relation.getType() != SampledRelation.Type.POISSONIZED) || relation.isRescaled())) { throw new SemanticException(SemanticErrorCode.SAMPLE_PERCENTAGE_OUT_OF_RANGE, relation.getSamplePercentage(), "Sample percentage must be less than or equal to 100"); if (relation.isRescaled() && !experimentalSyntaxEnabled) { throw new SemanticException(NOT_SUPPORTED, relation, "Rescaling is not enabled"); RelationType descriptor = process(relation.getRelation(), context);
@Override protected Void visitSampledRelation(SampledRelation node, Integer indent) { process(node.getRelation(), indent); builder.append(" TABLESAMPLE ") .append(node.getType()) .append(" (") .append(node.getSamplePercentage()) .append(')'); return null; }
@Override protected R visitSampledRelation(SampledRelation node, C context) { process(node.getRelation(), context); process(node.getSamplePercentage(), context); return null; }
@Override public Node visitSampledRelation(SqlBaseParser.SampledRelationContext context) { Relation child = (Relation) visit(context.aliasedRelation()); if (context.TABLESAMPLE() == null) { return child; } return new SampledRelation( getLocation(context), child, getSamplingMethod((Token) context.sampleType().getChild(0).getPayload()), (Expression) visit(context.percentage)); }
@Override protected RelationPlan visitSampledRelation(SampledRelation node, Void context) { if (node.getColumnsToStratifyOn().isPresent()) { throw new UnsupportedOperationException("STRATIFY ON is not yet implemented"); } RelationPlan subPlan = process(node.getRelation(), context); RelationType outputDescriptor = analysis.getOutputDescriptor(node); double ratio = analysis.getSampleRatio(node); Symbol sampleWeightSymbol = null; if (node.getType() == SampledRelation.Type.POISSONIZED) { sampleWeightSymbol = symbolAllocator.newSymbol("$sampleWeight", BIGINT); } PlanNode planNode = new SampleNode(idAllocator.getNextId(), subPlan.getRoot(), ratio, SampleNode.Type.fromType(node.getType()), node.isRescaled(), Optional.ofNullable(sampleWeightSymbol)); return new RelationPlan(planNode, outputDescriptor, subPlan.getOutputSymbols(), Optional.ofNullable(sampleWeightSymbol)); }
@Override protected Void visitSampledRelation(SampledRelation node, Integer indent) { process(node.getRelation(), indent); builder.append(" TABLESAMPLE ") .append(node.getType()) .append(" (") .append(node.getSamplePercentage()) .append(')'); return null; }