Examples of UpsertResult


Examples of com.socrata.model.UpsertResult

    @Test
    public void testParsingUpsertResults() throws IOException
    {

        UpsertResult noErrors = Soda2Producer.deserializeUpsertResult(new ByteArrayInputStream(UPSERT_RESULT_NO_ERRORS.getBytes("utf-8")));
        TestCase.assertEquals(0, noErrors.errorCount());
        TestCase.assertEquals(1, noErrors.getRowsCreated());
        TestCase.assertEquals(2, noErrors.getRowsUpdated());
        TestCase.assertEquals(3, noErrors.getRowsDeleted());

        UpsertResult errors1 = Soda2Producer.deserializeUpsertResult(new ByteArrayInputStream(UPSERT_RESULT_1.getBytes("utf-8")));
        TestCase.assertEquals(1, errors1.errorCount());
        TestCase.assertEquals(1, errors1.getErrors().get(0).getIndex());
        TestCase.assertEquals("Error1", errors1.getErrors().get(0).getError());
        TestCase.assertEquals("key1", errors1.getErrors().get(0).getPrimaryKey());
        TestCase.assertEquals(1, errors1.getRowsCreated());
        TestCase.assertEquals(2, errors1.getRowsUpdated());
        TestCase.assertEquals(3, errors1.getRowsDeleted());

        UpsertResult errors2 = Soda2Producer.deserializeUpsertResult(new ByteArrayInputStream(UPSERT_RESULT_2.getBytes("utf-8")));
        TestCase.assertEquals(2, errors2.errorCount());
        TestCase.assertEquals(1, errors2.getErrors().get(0).getIndex());
        TestCase.assertEquals("Error1", errors2.getErrors().get(0).getError());
        TestCase.assertEquals("key1", errors2.getErrors().get(0).getPrimaryKey());
        TestCase.assertEquals(2, errors2.getErrors().get(1).getIndex());
        TestCase.assertEquals("Error2", errors2.getErrors().get(1).getError());
        TestCase.assertEquals("key2", errors2.getErrors().get(1).getPrimaryKey());
        TestCase.assertEquals(1, errors2.getRowsCreated());
        TestCase.assertEquals(2, errors2.getRowsUpdated());
        TestCase.assertEquals(3, errors2.getRowsDeleted());
    }
View Full Code Here

Examples of com.socrata.model.UpsertResult

    @Test
    public void testParsingSodaServerUpsertResults() throws IOException
    {

        UpsertResult noErrors = Soda2Producer.deserializeUpsertResult(new ByteArrayInputStream(SODA_SERVER_UPSERT_RESULT_NO_ERRORS.getBytes("utf-8")));
        TestCase.assertEquals(0, noErrors.errorCount());
        TestCase.assertEquals(3, noErrors.getRowsCreated());
        TestCase.assertEquals(0, noErrors.getRowsUpdated());
        TestCase.assertEquals(0, noErrors.getRowsDeleted());

        UpsertResult errors1 = Soda2Producer.deserializeUpsertResult(new ByteArrayInputStream(SODA_SERVER_UPSERT_RESULT_1.getBytes("utf-8")));
        TestCase.assertEquals(1, errors1.errorCount());
        TestCase.assertEquals("error3", errors1.getErrors().get(0).getError());
        TestCase.assertEquals("key3", errors1.getErrors().get(0).getPrimaryKey());
        TestCase.assertEquals(0, errors1.getRowsCreated());
        TestCase.assertEquals(2, errors1.getRowsUpdated());
        TestCase.assertEquals(0, errors1.getRowsDeleted());

        UpsertResult errors2 = Soda2Producer.deserializeUpsertResult(new ByteArrayInputStream(SODA_SERVER_UPSERT_RESULT_2.getBytes("utf-8")));
        TestCase.assertEquals(2, errors2.errorCount());
        TestCase.assertEquals("error2", errors2.getErrors().get(0).getError());
        TestCase.assertEquals("key2", errors2.getErrors().get(0).getPrimaryKey());
        TestCase.assertEquals("error3", errors2.getErrors().get(1).getError());
        TestCase.assertEquals("key3", errors2.getErrors().get(1).getPrimaryKey());
        TestCase.assertEquals(0, errors2.getRowsCreated());
        TestCase.assertEquals(0, errors2.getRowsUpdated());
        TestCase.assertEquals(1, errors2.getRowsDeleted());
    }
View Full Code Here

Examples of com.socrata.model.UpsertResult

        //TestCase.assertTrue(EqualsBuilder.reflectionEquals(nominationUpdate, updatedNomination));

        List l = Lists.newArrayList(new DeleteRecord(objectMetadata.getId(), true));
        ObjectMapper m = new ObjectMapper();
        System.out.println(m.writeValueAsString(l));
        UpsertResult result = producer.upsert(UPDATE_DATA_SET, l);
        try {
            final Nomination deletedNomination = producer.getById(UPDATE_DATA_SET, objectMetadata.getId(), Nomination.class);
            TestCase.fail();
        } catch (DoesNotExistException e) {
            //Expected Condition
View Full Code Here

Examples of com.socrata.model.UpsertResult

      SoqlQuery myQuery =new SoqlQueryBuilder().setOffset(offset).build();
      response = streamExporter.query(sourceSetID, HttpLowLevel.JSON_TYPE, myQuery);
            rowSet = mapper.readValue(response.getEntityInputStream(), new TypeReference<List<Map<String,Object>>>() {});
      if (rowSet.size() > 0) {
                offset += rowSet.size();
                UpsertResult result = streamUpserter.upsert(sinkSetID, rowSet);
                rowsUpserted += result.getRowsCreated() + result.getRowsUpdated();
                System.out.println("\tUpserted " + rowsUpserted + " rows.");
            }
    } while (rowSet.size() > 0);
    }
View Full Code Here

Examples of com.socrata.model.UpsertResult

     * @return
     * @throws IOException
     */
    public JobStatus run() {
    SocrataConnectionInfo connectionInfo = userPrefs.getConnectionInfo();
    UpsertResult result = null;
        String publishExceptions = "";
        JobStatus runStatus = JobStatus.SUCCESS;

        JobStatus controlDeserialization = deserializeControlFile();
        if (controlDeserialization.isError() && (publishViaDi2Http || publishViaFTP)) {
            runStatus = controlDeserialization;
        } else {
            JobStatus validationStatus = IntegrationJobValidity.validateJobParams(connectionInfo, this);
            if (validationStatus.isError()) {
                runStatus = validationStatus;
            } else {
                Soda2Producer producer = null;
                try {
                    File fileToPublishFile = new File(fileToPublish);
                    if (publishViaDi2Http) {
                        try (DeltaImporter2Publisher publisher = new DeltaImporter2Publisher(userPrefs)) {
                            // "upsert" == "append" in di2
                            if ("upsert".equalsIgnoreCase(controlFile.action))
                                controlFile.action = "Append";
                            // TODO: remove the next line when di2 is updated to accept lowercase variants
                            controlFile.action = Utils.capitalizeFirstLetter(controlFile.action);
                            runStatus = publisher.publishWithDi2OverHttp(datasetID, fileToPublishFile, controlFile);
                        }
                    } else if (publishViaFTP) {
                        runStatus = doPublishViaFTPv2(fileToPublishFile);
                    } else {
                        // attach a requestId to all Producer API calls (for error tracking purposes)
                        String jobRequestId = Utils.generateRequestId();
                        producer = Soda2Producer.newProducerWithRequestId(
                                connectionInfo.getUrl(), connectionInfo.getUser(), connectionInfo.getPassword(), connectionInfo.getToken(), jobRequestId);
                        final SodaImporter importer = SodaImporter.newImporter(connectionInfo.getUrl(), connectionInfo.getUser(), connectionInfo.getPassword(), connectionInfo.getToken());
                        int filesizeChunkingCutoffBytes = userPrefs.getFilesizeChunkingCutoffMB() == null ? 10 * NUM_BYTES_PER_MB :
                                Integer.parseInt(userPrefs.getFilesizeChunkingCutoffMB()) * NUM_BYTES_PER_MB;
                        int numRowsPerChunk = userPrefs.getNumRowsPerChunk() == null ? 10000 :
                                Integer.parseInt(userPrefs.getNumRowsPerChunk());
                        switch (publishMethod) {
                            case upsert:
                            case append:
                                result = doAppendOrUpsertViaHTTP(
                                        producer, importer, fileToPublishFile, filesizeChunkingCutoffBytes, numRowsPerChunk);
                                break;
                            case replace:
                                result = Soda2Publisher.replaceNew(
                                        producer, importer, datasetID, fileToPublishFile, fileToPublishHasHeaderRow);
                                break;
                            case delete:
                                result = doDeleteViaHTTP(
                                        producer, importer, fileToPublishFile, filesizeChunkingCutoffBytes, numRowsPerChunk);
                                break;
                            default:
                                runStatus = JobStatus.INVALID_PUBLISH_METHOD;
                        }
                    }

                } catch (IOException | SodaError | InterruptedException e) {
                    publishExceptions = e.getMessage();
                    e.printStackTrace();
                } finally {
                    if (producer != null) producer.close();
                }
            }
        }

        if (publishExceptions.length() > 0) {
            runStatus = JobStatus.PUBLISH_ERROR;
            runStatus.setMessage(publishExceptions);
        } else if (result != null && result.errorCount() > 0) {  // Check for [row-level] SODA 2 errors
            runStatus = craftSoda2PublishError(result);
        }

        String logPublishingErrorMessage = logRunResults(runStatus, result);
        emailAdmin(runStatus, logPublishingErrorMessage);
View Full Code Here

Examples of com.socrata.model.UpsertResult

        }
    }

    private UpsertResult doAppendOrUpsertViaHTTP(Soda2Producer producer, SodaImporter importer, File fileToPublishFile, int filesizeChunkingCutoffBytes, int numRowsPerChunk) throws SodaError, InterruptedException, IOException {
        int numberOfRows = numRowsPerChunk(fileToPublishFile, filesizeChunkingCutoffBytes, numRowsPerChunk);
        UpsertResult result = Soda2Publisher.appendUpsert(
                producer, importer, datasetID, fileToPublishFile, numberOfRows, fileToPublishHasHeaderRow);
        return result;
    }
View Full Code Here

Examples of com.socrata.model.UpsertResult

    private UpsertResult doDeleteViaHTTP(
            Soda2Producer producer, SodaImporter importer, File fileToPublishFile, int filesizeChunkingCutoffBytes, int numRowsPerChunk)
            throws SodaError, InterruptedException, IOException {
        int numberOfRows = numRowsPerChunk(fileToPublishFile, filesizeChunkingCutoffBytes, numRowsPerChunk);
        UpsertResult result = Soda2Publisher.deleteRows(
                producer, importer, datasetID, fileToPublishFile, numberOfRows, fileToPublishHasHeaderRow);
        return result;
    }
View Full Code Here

Examples of com.socrata.model.UpsertResult

            currLine = reader.readNext();
            if(currLine != null) {
                upsertObjectsChunk.add(ImmutableMap.of(rowIdentifierName, (Object) currLine[0], ":deleted", Boolean.TRUE));
            }
            if(upsertObjectsChunk.size() == numRowsPerChunk || currLine == null) {
                UpsertResult chunkResult = producer.upsert(id, upsertObjectsChunk);
                totalRowsDeleted += chunkResult.getRowsDeleted();

                if(chunkResult.errorCount() > 0) {
                    // TODO find a better way to suppress these errors (which are really not errors anyway)
                    for(UpsertError err : chunkResult.getErrors()) {
                        if(!err.getError().contains("no record is found")) {
                            deleteErrors.add(err);
                        }
                    }
                }
                upsertObjectsChunk.clear();
            }
        } while(currLine != null);
        reader.close();

        return new UpsertResult(
                0, 0, totalRowsDeleted, deleteErrors);
    }
View Full Code Here

Examples of com.socrata.model.UpsertResult

                    } else {
                        System.out.println("Publishing file in chunks via HTTP (" + numUploadedChunks * numRowsPerChunk + " rows uploaded so far)...");
                    }

                    // upsert or replace current chunk
                    UpsertResult chunkResult;
                    if(method.equals(PublishMethod.upsert) || method.equals(PublishMethod.append)) {
                        chunkResult = producer.upsert(id, upsertObjectsChunk);
                    } else if(method.equals(PublishMethod.replace)) {
                        chunkResult = producer.replace(id, upsertObjectsChunk);
                    } else {
                        reader.close();
                        throw new IllegalArgumentException("Error performing publish: "
                                + method + " is not a valid publishing method");
                    }
                    totalRowsCreated += chunkResult.getRowsCreated();
                    totalRowsUpdated += chunkResult.getRowsUpdated();
                    totalRowsDeleted += chunkResult.getRowsDeleted();
                    numUploadedChunks += 1;

                    if(chunkResult.errorCount() > 0) {
                        if(numRowsPerChunk != 0) {
                            for (UpsertError upsertErr : chunkResult.getErrors()) {
                                int lineIndexOffset = (containsHeaderRow) ? 2 : 1;
                                System.err.println("Error uploading chunk " + numUploadedChunks + ": " +
                                        upsertErr.getError() + " (line " +
                                        (upsertErr.getIndex() + lineIndexOffset + ((numUploadedChunks-1) * numRowsPerChunk)) + " of file)");
                            }
                        }
                        upsertErrors.addAll(chunkResult.getErrors());
                    }

                    if(numRowsPerChunk != 0) {
                        System.out.println("Chunk " + numUploadedChunks + " uploaded: " + chunkResult.getRowsCreated() + " rows created; " +
                                chunkResult.getRowsUpdated() + " rows updated; " + chunkResult.getRowsDeleted() +
                                " rows deleted; " + chunkResult.errorCount() + " rows omitted");
                    }

                    upsertObjectsChunk.clear();
                }
            } while(currLine != null);
        }
        reader.close();
        return new UpsertResult(
                totalRowsCreated, totalRowsUpdated, totalRowsDeleted, upsertErrors);
    }
View Full Code Here

Examples of com.socrata.model.UpsertResult

    public void testReplaceNew() throws LongRunningQueryException, SodaError, IOException, InterruptedException {
        final Soda2Producer producer = createProducer();
        final SodaDdl ddl = createSodaDdl();

        File twoRowsFile = new File("src/test/resources/datasync_unit_test_two_rows.csv");
        UpsertResult result = Soda2Publisher.replaceNew(producer, ddl, UNITTEST_DATASET_ID, twoRowsFile, true);

        TestCase.assertEquals(0, result.errorCount());
        TestCase.assertEquals(2, result.getRowsCreated());
        TestCase.assertEquals(2, getTotalRows(UNITTEST_DATASET_ID));
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.