private void parse()

in src/main/java/com/aliyun/odps/jdbc/OdpsPreparedStatement.java [205:265]


  private void parse() throws SQLException {

    boolean withSpecPartition = sql.matches(PREP_INSERT_WITH_SPEC_PARTITION);
    boolean withoutSpecPartition = sql.matches(PREP_INSERT_WITHOUT_SPEC_PARTITION);

    if (!withoutSpecPartition && !withSpecPartition) {
      throw new SQLException("batched statement only support following syntax: " + EXAMPLE);
    }

    Matcher matcher = null;
    boolean hasPartition = false;

    if (withoutSpecPartition) {
      matcher = Pattern.compile(PREP_INSERT_WITHOUT_SPEC_PARTITION).matcher(sql);
      hasPartition = false;
    }

    if (withSpecPartition) {
      matcher = Pattern.compile(PREP_INSERT_WITH_SPEC_PARTITION).matcher(sql);
      hasPartition = true;
    }


    if (matcher.find()) {
      tableBatchInsertTo = matcher.group(1);
      if (hasPartition) {
        partitionSpec = matcher.group(4);
      }
      if (tableBatchInsertTo.contains(".")) {
        String[] splited = tableBatchInsertTo.split("\\.");
        projectName = splited[0];
        tableName = splited[1];
      } else {
        projectName = getConnection().getOdps().getDefaultProject();
        tableName = tableBatchInsertTo;
      }
    } else {
      throw new SQLException("cannot extract table name or partition name in SQL: " + sql);
    }
    List<String> specificColumns =
        Optional.ofNullable(matcher.group(3)).map(s -> s.substring(1, s.length() - 1))
            .map(s -> s.split(","))
            .map(s -> Arrays.stream(s).map(String::trim).collect(Collectors.toList())).orElse(null);
    if (specificColumns != null) {
      if (specificColumns.size() != batchedRows.get(0).length) {
        throw new SQLException(
            "sql has specific " + specificColumns + " columns, but only prepare " + batchedRows.get(
                0).length + " values");
      }
      this.specificColumns = specificColumns;
    }

    try {
      uploader = DataUploader.build(projectName, schemaName, tableName, partitionSpec,
                                    specificColumns, getConnection());
    } catch (OdpsException | IOException e) {
      throw new SQLException(e.getMessage());
    }

    parsed = true;
  }