dayname translation

@param buf The buffer to append into
@param parsedArgs arguments
@throws SQLException if something wrong happens
421944
public static void sqldayname(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException {
    if (parsedArgs.size() != 1) {
      throw new PSQLException(GT.tr("{0} function takes one and only one argument.", "dayname"),
          PSQLState.SYNTAX_ERROR);
    }
    appendCall(buf, "to_char(", ",", ",'Day')", parsedArgs);
  }
1148760
public static void sqldatabase(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException {
    zeroArgumentFunctionCall(buf, "current_database()", "database", parsedArgs);
  }
1209756
static void setParameters(PreparedStatement ps, List<Parameter> params, boolean namesAllowed)
            throws SQLException {
        for (int i = 1; i <= params.size(); i++) {
            if (params.get(i - 1).hasName() && !namesAllowed)
                throw new SQLException("named parameter found but sql does not contain names");
            Object o = params.get(i - 1).value();
            try {
                if (o == null)
                    ps.setObject(i, null);
                else if (o == Database.NULL_CLOB)
                    ps.setNull(i, Types.CLOB);
                else if (o == Database.NULL_BLOB)
                    ps.setNull(i, Types.BLOB);
                else {
                    Class<?> cls = o.getClass();
                    if (Clob.class.isAssignableFrom(cls)) {
                        setClob(ps, i, o, cls);
                    } else if (Blob.class.isAssignableFrom(cls)) {
                        setBlob(ps, i, o, cls);
                    } else if (Calendar.class.isAssignableFrom(cls)) {
                        Calendar cal = (Calendar) o;
                        Timestamp t = new java.sql.Timestamp(cal.getTimeInMillis());
                        ps.setTimestamp(i, t, cal);
                    } else if (Time.class.isAssignableFrom(cls)) {
                        Calendar cal = Calendar.getInstance();
                        ps.setTime(i, (Time) o, cal);
                    } else if (Timestamp.class.isAssignableFrom(cls)) {
                        Calendar cal = Calendar.getInstance();
                        ps.setTimestamp(i, (Timestamp) o, cal);
                    } else if (java.sql.Date.class.isAssignableFrom(cls)) {
                        Calendar cal = Calendar.getInstance();
                        ps.setDate(i, (java.sql.Date) o, cal);
                    } else if (java.util.Date.class.isAssignableFrom(cls)) {
                        Calendar cal = Calendar.getInstance();
                        java.util.Date date = (java.util.Date) o;
                        ps.setTimestamp(i, new java.sql.Timestamp(date.getTime()), cal);
                    } else
                        ps.setObject(i, o);
                }
            } catch (SQLException e) {
                log.debug("{} when setting ps.setObject({},{})", e.getMessage(), i, o);
                throw e;
            }
        }
    }
1252460
function quoteIdent(value) {

    if (value === undefined || value === null) {
        throw new Error('SQL identifier cannot be null or undefined');
    } else if (value === false) {
        return '"f"';
    } else if (value === true) {
        return '"t"';
    } else if (value instanceof Date) {
        return '"' + formatDate(value.toISOString()) + '"';
    } else if (value instanceof Buffer) {
        throw new Error('SQL identifier cannot be a buffer');
    } else if (Array.isArray(value) === true) {
        var temp = [];
        for (var i = 0; i < value.length; i++) {
            if (Array.isArray(value[i]) === true) {
                throw new Error('Nested array to grouped list conversion is not supported for SQL identifier');
            } else {
                temp.push(quoteIdent(value[i]));
            }
        }
        return temp.toString();
    } else if (value === Object(value)) {
        throw new Error('SQL identifier cannot be an object');
    }

    var ident = value.toString().slice(0); // create copy

    // do not quote a valid, unquoted identifier
    if (/^[a-z_][a-z0-9_$]*$/.test(ident) === true && isReserved(ident) === false) {
        return ident;
    }

    var quoted = '"';

    for (var i = 0; i < ident.length; i++) {
        var c = ident[i];
        if (c === '"') {
            quoted += c + c;
        } else {
            quoted += c;
        }
    }

    quoted += '"';

    return quoted;
}
1226626
public <T> T querySingleTypedResult(String sql, String[] args) {
		@SuppressWarnings("unchecked")
		T result = (T) querySingleResult(sql, args);
		return result;
	}
1353487
private void processCalendars() throws SQLException
   {
      List<Row> rows = getRows("select * from " + m_schema + "calendar where (proj_id is null or proj_id=?) and delete_date is null", m_projectID);
      m_reader.processCalendars(rows);
   }
820131
public StringBuffer format(Calendar calendar, StringBuffer buf) {
        if (mTimeZoneForced) {
            calendar.getTime(); /// LANG-538
            calendar = (Calendar) calendar.clone();
            calendar.setTimeZone(mTimeZone);
        }
        return applyRules(calendar, buf);
    }
979060
protected String processNamedArgument(
            final Map<String, Object> argBindings,
            final NamedArgumentDefinition argDef,
            final String fieldCommentText) {
        // Retrieve default value
        final Object fieldValue = argDef.getArgumentValue();
        argBindings.put("defaultValue",
                fieldValue == null ?
                        argDef.getDefaultValueAsString() :
                        prettyPrintValueString(fieldValue));

        if (fieldValue instanceof Number) {
            // Retrieve min and max / hard and soft value thresholds for numeric args
            argBindings.put("minValue", argDef.getMinValue());
            argBindings.put("maxValue", argDef.getMaxValue());
            argBindings.put("minRecValue",
                    argDef.getMinRecommendedValue() != Double.NEGATIVE_INFINITY ?
                            argDef.getMinRecommendedValue() :
                            "NA");
            argBindings.put("maxRecValue",
                    argDef.getMaxRecommendedValue() != Double.POSITIVE_INFINITY ?
                            argDef.getMaxRecommendedValue() :
                            "NA");
        } else {
            argBindings.put("minValue", "NA");
            argBindings.put("maxValue", "NA");
            argBindings.put("minRecValue", "NA");
            argBindings.put("maxRecValue", "NA");
        }

        // Add in the number of times you can specify it:
        argBindings.put("minElements", argDef.getMinElements());
        argBindings.put("maxElements", argDef.getMaxElements());

        final String kind = docKindOfArg(argDef);
        argBindings.put("kind", kind);

        final Pair<String, String> names = displayNames(argDef.getShortName(), argDef.getLongName());
        argBindings.put("name", names.getLeft());
        argBindings.put("synonyms", names.getRight() != null ? names.getRight() : "NA");
        argBindings.put("required", argDef.isOptional() ? "no": "yes") ;
        argBindings.put("type", argumentTypeString(argDef.getUnderlyingField().getGenericType()));

        // summary and fulltext
        argBindings.put("summary", argDef.getDocString() != null ? argDef.getDocString() : "");
        argBindings.put("fulltext", fieldCommentText);

        // Does this argument interact with any others?
        if (argDef.isControlledByPlugin()) {
            argBindings.put("otherArgumentRequired",
                    argDef.getContainingObject().getClass().getSimpleName().length() == 0 ?
                            argDef.getContainingObject().getClass().getName() :
                            argDef.getContainingObject().getClass().getSimpleName());
        } else {
            argBindings.put("otherArgumentRequired", "NA");
        }

        argBindings.put("exclusiveOf",
                argDef.getMutexTargetList() != null && !argDef.getMutexTargetList().isEmpty() ?
                    String.join(", ", argDef.getMutexTargetList()) :
                    "NA");

        // enum options
        argBindings.put("options",
                argDef.getUnderlyingField().getType().isEnum() ?
                        docForEnumArgument(argDef.getUnderlyingField().getType()) :
                        Collections.EMPTY_LIST);

        List<String> attributes = new ArrayList<>();
        if (!argDef.isOptional()) {
            attributes.add("required");
        }
        if (argDef.isDeprecated()) {
            attributes.add("deprecated");
        }
        argBindings.put("attributes", attributes.size() > 0 ? String.join(", ", attributes) : "NA");

        return kind;
    }
208258
public static void main(String[] args) throws Exception {
		
		if(!parseParameters(args)) {
			return;
		}

		final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

		// get input data
		DataSet<Lineitem> li = getLineitemDataSet(env);
		DataSet<Order> or = getOrdersDataSet(env);
		DataSet<Customer> cust = getCustomerDataSet(env);
		
		// Filter market segment "AUTOMOBILE"
		cust = cust.filter(
							new FilterFunction<Customer>() {
								@Override
								public boolean filter(Customer value) {
									return value.getMktsegment().equals("AUTOMOBILE");
								}
							});

		// Filter all Orders with o_orderdate < 12.03.1995
		or = or.filter(
						new FilterFunction<Order>() {
							private DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
							private Date date;
							
							{	
								Calendar cal = Calendar.getInstance();
								cal.set(1995, 3, 12);
								date = cal.getTime(); 
							}
							
							@Override
							public boolean filter(Order value) throws ParseException {
								Date orderDate = format.parse(value.getOrderdate());
								return orderDate.before(date);
							}
						});
		
		// Filter all Lineitems with l_shipdate > 12.03.1995
		li = li.filter(
						new FilterFunction<Lineitem>() {
							private DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
							private Date date;
							
							{
								Calendar cal = Calendar.getInstance();
								cal.set(1995, 3, 12);
								date = cal.getTime();
							}
							
							@Override
							public boolean filter(Lineitem value) throws ParseException {
								Date shipDate = format.parse(value.getShipdate());
								return shipDate.after(date);
							}
						});

		// Join customers with orders and package them into a ShippingPriorityItem
		DataSet<ShippingPriorityItem> customerWithOrders = 
				cust.join(or)
					.where(0)
					.equalTo(0)
					.with(
							new JoinFunction<Customer, Order, ShippingPriorityItem>() {
								@Override
								public ShippingPriorityItem join(Customer first, Order second) {
									return new ShippingPriorityItem(0, 0.0, second.getOrderdate(),
											second.getShippriority(), second.getOrderkey());
								}
							});
		
		// Join the last join result with Lineitems
		DataSet<ShippingPriorityItem> joined = 
				customerWithOrders.join(li)
									.where(4)
									.equalTo(0)
									.with(
											new JoinFunction<ShippingPriorityItem, Lineitem, ShippingPriorityItem>() {
												@Override
												public ShippingPriorityItem join(ShippingPriorityItem first, Lineitem second) {
													first.setL_Orderkey(second.getOrderkey());
													first.setRevenue(second.getExtendedprice() * (1 - second.getDiscount()));
													return first;
												}
											});
		
		// Group by l_orderkey, o_orderdate and o_shippriority and compute revenue sum
		joined = joined
				.groupBy(0, 2, 3)
				.aggregate(Aggregations.SUM, 1);
		
		// emit result
		joined.writeAsCsv(outputPath, "\n", "|");
		
		// execute program
		env.execute("TPCH Query 3 Example");
		
	}
1149896
public static void sqlquarter(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException {
    singleArgumentFunctionCall(buf, "extract(quarter from ", "quarter", parsedArgs);
  }
575624
@Override
  public StringBuilder appendToBuffer(StringBuilder buf) {
    buf.append(getTask());
    buf.append(": ");
    buf.append(getProcessed());
    return buf;
  }
1082052
public static void quote(StringBuilder buf, String arg)
   {
      if (!mightNeedQuotes(arg)) {
         buf.append(arg);
         return;
      }
      buf.append('"');

      // The length of the current run of backslashes.
      int nPending = 0;

      for (int i = 0; i < arg.length(); i++) {
         char c = arg.charAt(i);

         if (c == '\\') {
            nPending++;
         }
         else {
            if (c == '"') {
               // Escape all the backslashes we've collected up till now.
               for (int j = 0; j < nPending; j++) {
                  buf.append('\\');
               }
               // Escape the quote.
               buf.append('\\');
            }
            nPending = 0;
         }

         buf.append(c);
      }

      // Escape all the backslashes that appear before the final closing quote.
      for (int j = 0; j < nPending; j++) {
         buf.append('\\');
      }

      buf.append('"');
   }
566738
@Override
	public String doTransformSql(final SqlContext sqlContext, final String sql) {
		if (getFilters().isEmpty()) {
			return sql;
		}
		String newSql = sql;
		for (final SqlFilter filter : getFilters()) {
			newSql = filter.doTransformSql(sqlContext, newSql);
		}
		return newSql;
	}
587568
public static void sqltimestampdiff(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException {
    if (parsedArgs.size() != 3) {
      throw new PSQLException(
          GT.tr("{0} function takes three and only three arguments.", "timestampdiff"),
          PSQLState.SYNTAX_ERROR);
    }
    buf.append("extract( ")
        .append(constantToDatePart(buf, parsedArgs.get(0).toString()))
        .append(" from (")
        .append(parsedArgs.get(2))
        .append("-")
        .append(parsedArgs.get(1))
        .append("))");
  }
514438
public static void sqlcurtime(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException {
    zeroArgumentFunctionCall(buf, "current_time", "curtime", parsedArgs);
  }
624638
public static String sqlinsert(List<?> parsedArgs) throws SQLException {
    if (parsedArgs.size() != 4) {
      throw new PSQLException(GT.tr("{0} function takes four and only four argument.", "insert"),
          PSQLState.SYNTAX_ERROR);
    }
    StringBuilder buf = new StringBuilder();
    buf.append("overlay(");
    buf.append(parsedArgs.get(0)).append(" placing ").append(parsedArgs.get(3));
    buf.append(" from ").append(parsedArgs.get(1)).append(" for ").append(parsedArgs.get(2));
    return buf.append(')').toString();
  }
156801
static void appendConstant(final StringBuffer buf, final Object cst) {
        if (cst == null) {
            buf.append("null");
        } else if (cst instanceof String) {
            appendString(buf, (String) cst);
        } else if (cst instanceof Type) {
            buf.append("Type.getType(\"");
            buf.append(((Type) cst).getDescriptor());
            buf.append("\")");
        } else if (cst instanceof Handle) {
            buf.append("new Handle(");
            Handle h = (Handle) cst;
            buf.append("Opcodes.").append(HANDLE_TAG[h.getTag()])
                    .append(", \"");
            buf.append(h.getOwner()).append("\", \"");
            buf.append(h.getName()).append("\", \"");
            buf.append(h.getDesc()).append("\")");
        } else if (cst instanceof Byte) {
            buf.append("new Byte((byte)").append(cst).append(')');
        } else if (cst instanceof Boolean) {
            buf.append(((Boolean) cst).booleanValue() ? "Boolean.TRUE"
                    : "Boolean.FALSE");
        } else if (cst instanceof Short) {
            buf.append("new Short((short)").append(cst).append(')');
        } else if (cst instanceof Character) {
            int c = ((Character) cst).charValue();
            buf.append("new Character((char)").append(c).append(')');
        } else if (cst instanceof Integer) {
            buf.append("new Integer(").append(cst).append(')');
        } else if (cst instanceof Float) {
            buf.append("new Float(\"").append(cst).append("\")");
        } else if (cst instanceof Long) {
            buf.append("new Long(").append(cst).append("L)");
        } else if (cst instanceof Double) {
            buf.append("new Double(\"").append(cst).append("\")");
        } else if (cst instanceof byte[]) {
            byte[] v = (byte[]) cst;
            buf.append("new byte[] {");
            for (int i = 0; i < v.length; i++) {
                buf.append(i == 0 ? "" : ",").append(v[i]);
            }
            buf.append('}');
        }