/** * Creates a new user exception builder . * * @see com.dremio.exec.proto.UserBitShared.DremioPBError.ErrorType#FUNCTION * @return user exception builder */ public static Builder functionError() { return functionError(null); }
ExceptionBuilderImpl() { b = UserException.functionError(); }
ExceptionBuilderImpl(final Throwable cause) { b = UserException.functionError(cause); }
public void close(){ if(!errors.isEmpty()){ throw UserException.functionError().message(Joiner.on("\n").join(errors)).build(logger); } }
@Override public CompleteType getOutputType(CompleteType baseReturn, List<LogicalExpression> args) { if (args.size() != 3 || !(args.get(1) instanceof LongExpression) || !(args.get(2) instanceof LongExpression) ) { throw UserException.functionError().message("Attempted to cast decimal function with inccorect number of arguments. Expected 3 arguments (value, scale, precision) but received %d arguments.", args.size()).build(logger); } int precision = (int) ((LongExpression)(args.get(1))).getLong(); int scale = (int) ((LongExpression)(args.get(2))).getLong(); return CompleteType.fromDecimalPrecisionScale(precision, scale); } };
/** * For Extract and date_part functions, infer the return types based on timeUnit */ public static SqlTypeName getSqlTypeNameForTimeUnit(String timeUnit) { switch (timeUnit.toUpperCase()){ case "YEAR": case "MONTH": case "DAY": case "HOUR": case "MINUTE": case "SECOND": case "CENTURY": case "DECADE": case "DOW": case "DOY": case "MILLENNIUM": case "QUARTER": case "WEEK": case "EPOCH": return SqlTypeName.BIGINT; default: throw UserException .functionError() .message("extract function supports the following time units: YEAR, MONTH, DAY, HOUR, MINUTE, SECOND") .build(logger); } }
private static void verifyClassUnicity(List<AnnotatedClassDescriptor> annotatedClasses, Collection<URL> pathsScanned) { Set<String> scanned = new HashSet<>(); for (AnnotatedClassDescriptor annotated : annotatedClasses) { if (!scanned.add(annotated.getClassName())) { throw UserException.functionError() .message( "function %s scanned twice in the following locations:\n" + "%s\n" + "Do you have conflicting jars on the classpath?", annotated.getClassName(), pathsScanned ) .build(logger); } } }
private int numTilesFromExpression(LogicalExpression numTilesExpr) { if ((numTilesExpr instanceof ValueExpressions.IntExpression)) { int nt = ((ValueExpressions.IntExpression) numTilesExpr).getInt(); if (nt > 0) { return nt; } } throw UserException.functionError().message("NTILE only accepts positive integer argument").build(logger); }
protected static List<SearchFieldSorting> buildSorter(final String shortKey, final SortOrder order) { if (shortKey != null) { final IndexKey key = JobIndexKeys.MAPPING.getKey(shortKey); if(key == null || !key.isSorted()){ throw UserException.functionError().message("Unable to sort by field {}.", shortKey).build(logger); } return ImmutableList.of(key.toSortField(order)); } return DEFAULT_SORTER; }
@Override public CompleteType getOutputType(CompleteType baseReturn, List<LogicalExpression> args) { if (args.size() != 2) { throw UserException.functionError().message("Attempted to add a decimal value with inccorect number of arguments. Expected two but received %d arguments.", args.size()).build(logger); } LogicalExpression left = args.get(0); LogicalExpression right = args.get(1); // compute the output scale and precision here int outputScale = Math.max(scale(left), scale(right)); int maxResultIntegerDigits = Math.max((prec(left) - scale(left)), (prec(right) - scale(right))) + 1; int outputPrecision = (outputScale + maxResultIntegerDigits); // If we are beyond the maximum precision range, cut down the fractional part if (outputPrecision > 38) { outputPrecision = 38; outputScale = (outputPrecision - maxResultIntegerDigits >= 0) ? (outputPrecision - maxResultIntegerDigits) : 0; } return CompleteType.fromDecimalPrecisionScale(outputPrecision, outputScale); } };
@Override public void consumeData(int records) throws Exception { aggregator.addBatch(records); if (isCardinalityLimited && aggregator.numHashTableEntries() > cardinalityLimit) { throw UserException.functionError() .message("Computing the min() or max() measures of variable-length columns only supported for low-cardinality aggregations") .build(logger); } }
throw UserException.functionError() .message("Failure reading Function class. No methods were found.") .addContext("Function Class", className) throw UserException.functionError(e) .message("Failure reading Function class.") .addContext("Function Class", className)
private static SearchFieldSorting buildSorter(final String sortColumn, final SortOrder order) { if(sortColumn == null){ return DEFAULT_SORTER; } final IndexKey key = UserIndexKeys.MAPPING.getKey(sortColumn); if(key == null){ throw UserException .functionError() .message("Unable to sort by field {}", sortColumn) .build(logger); } return key.toSortField(order); }
public CompleteType getOutputType(CompleteType baseReturn, List<LogicalExpression> args) { if (args.size() != 2) { throw UserException.functionError().message("Attempted to cast decimal function with inccorect number of arguments. Expected 3 arguments (value, scale, precision) but received %d arguments.", args.size()).build(logger); } LogicalExpression left = args.get(0); LogicalExpression right = args.get(1); int outputScale = scale(left) + scale(right); int integerDigits = (prec(left) - scale(left)) + (prec(right) - scale(right)); int outputPrecision = integerDigits + outputScale; // If we are beyond the maximum precision range, cut down the fractional part if (outputPrecision > 38) { outputPrecision = 38; outputScale = (outputPrecision - integerDigits >= 0) ? (outputPrecision - integerDigits) : 0; } return CompleteType.fromDecimalPrecisionScale(outputPrecision, outputScale); } };
private static DateTimeFormatter getFormatterInternal(final String formatString, final Chronology chronology) { final String jodaString; try { jodaString = JodaDateValidator.toJodaFormat(formatString); } catch (ParseException e) { throw UserException.functionError(e) .message("Failure parsing the formatting string at column %d of: %s", e.getErrorOffset(), formatString) .addContext("Details", e.getMessage()) .addContext("Format String", formatString) .addContext("Error Offset", e.getErrorOffset()) .build(logger); } try { return DateTimeFormat.forPattern(jodaString) .withChronology(chronology); } catch (IllegalArgumentException ex) { throw UserException.functionError(ex) .message("Invalid formatting string") .addContext("Details", ex.getMessage()) .addContext("Format String", formatString) .build(logger); } }
public CompleteType getOutputType(CompleteType baseReturn, List<LogicalExpression> args) { Preconditions.checkArgument(args.size() == 1); CompleteType type = args.get(0).getCompleteType(); if(!type.isStruct()){ throw UserException.functionError() .message("The kvgen function can only be used when operating against maps. The type you were attempting to apply it to was a %s.", type.toString()) .build(logger); } List<Field> children = type.getChildren(); if(children.isEmpty()){ throw UserException.functionError() .message("The kvgen function can only be used when operating against maps. The type you were attempting to apply it to was a %s.", type.toString()) .build(logger); } CompleteType valueType = CompleteType.fromField(children.get(0)); for(int i =0; i < children.size(); i++){ valueType = valueType.merge(CompleteType.fromField(children.get(i))); } return new CompleteType( ArrowType.List.INSTANCE, new CompleteType( ArrowType.Struct.INSTANCE, CompleteType.VARCHAR.toField(MappifyUtility.fieldKey), valueType.toField(MappifyUtility.fieldValue)) .toField("$data$")); } }
protected String meth(String methodName, boolean required) { String method = initializer.getMethod(methodName); if (method == null) { if (!required) { return ""; } long count = initializer.getCount(); Collection<String> methods = initializer.getMethodNames(); throw UserException .functionError() .message("Failure while trying use function. No body found for required method %s. Count %d, Methods that were available %s", methodName, count, methods) .addContext("FunctionClass", initializer.getClassName()) .build(logger); } return method; }
private static BaseFunctionHolder resolveFunctionHolder(final SqlOperatorBinding opBinding, final List<BaseFunctionHolder> functions) { final FunctionCall functionCall = convertSqlOperatorBindingToFunctionCall(opBinding); final FunctionResolver functionResolver = FunctionResolverFactory.getResolver(functionCall); final BaseFunctionHolder func = functionResolver.getBestMatch(functions, functionCall); // Throw an exception // if no BaseFunctionHolder matched for the given list of operand types if(func == null) { String operandTypes = ""; for(int i = 0; i < opBinding.getOperandCount(); ++i) { operandTypes += opBinding.getOperandType(i).getSqlTypeName(); if(i < opBinding.getOperandCount() - 1) { operandTypes += ","; } } throw UserException .functionError() .message(String.format("%s does not support operand types (%s)", opBinding.getOperator().getName(), operandTypes)) .build(logger); } return func; }
.functionError() .message(String.format("%s does not support operand types (%s)", opBinding.getOperator().getName(),
public static WindowFunction fromExpression(final NamedExpression expr) { if (!(expr.getExpr() instanceof FunctionCall)) { throw UserException.functionError() .message("Unsupported window function '%s'", expr.getExpr()) .build(logger);