private boolean applies(SchemaContext sc, DMLStatement stmt) throws PEException { if (stmt instanceof UpdateStatement) { UpdateStatement us = (UpdateStatement) stmt; for (Iterator<ExpressionNode> iter = us.getUpdateExpressionsEdge().iterator(); iter.hasNext(); ) { FunctionCall fc = (FunctionCall) iter.next(); ColumnInstance lhs = (ColumnInstance) fc.getParametersEdge().get(0); if (lhs.getPEColumn().isPartOfContainerDistributionVector()) throw new SchemaException( new ErrorInfo( AvailableErrors.INVALID_CONTAINER_DISCRIMINANT_COLUMN_UPDATE, lhs.getPEColumn().getName().getUnquotedName().get(), lhs.getPEColumn().getTable().getName().getUnquotedName().get())); } return false; } else if (stmt instanceof DeleteStatement) { DeleteStatement ds = (DeleteStatement) stmt; PETable pet = ds.getTargetDeleteEdge().get().getAbstractTable().asTable(); if (pet.isContainerBaseTable(sc)) { List<Part> parts = DiscriminantCollector.getDiscriminants(sc, ds.getWhereClause()); if (parts == null || parts.isEmpty()) throw new SchemaException( new ErrorInfo( AvailableErrors.INVALID_CONTAINER_DELETE, pet.getName().getUnquotedName().get())); else { List<SchemaCacheKey<PEContainerTenant>> matchingTenants = convert(sc, parts); stmt.getBlock().store(ContainerBaseTableRewriteTransformFactory.class, matchingTenants); return true; } } return false; } return false; }
private List<SchemaCacheKey<PEContainerTenant>> getPertinentTenants( PlannerContext pc, DMLStatement stmt) throws PEException { SchemaContext sc = pc.getContext(); if (stmt instanceof UpdateStatement) { UpdateStatement us = (UpdateStatement) stmt; for (Iterator<ExpressionNode> iter = us.getUpdateExpressionsEdge().iterator(); iter.hasNext(); ) { FunctionCall fc = (FunctionCall) iter.next(); ColumnInstance lhs = (ColumnInstance) fc.getParametersEdge().get(0); if (lhs.getPEColumn().isPartOfContainerDistributionVector()) throw new SchemaException( Pass.PLANNER, "Invalid update: discriminant column " + lhs.getPEColumn().getName().getSQL() + " of container base table " + lhs.getPEColumn().getTable().getName().getSQL() + " cannot be updated"); } } else if (stmt instanceof DeleteStatement) { DeleteStatement ds = (DeleteStatement) stmt; PETable pet = ds.getTargetDeleteEdge().get().getAbstractTable().asTable(); if (pet.isContainerBaseTable(sc)) { List<Part> parts = DiscriminantCollector.getDiscriminants(sc, ds.getWhereClause()); if (parts == null || parts.isEmpty()) throw new SchemaException( Pass.PLANNER, "Invalid delete on container base table " + pet.getName().getSQL() + ". Not restricted by discriminant columns"); else { List<SchemaCacheKey<PEContainerTenant>> matchingTenants = convert(sc, parts); return matchingTenants; } } } return null; }