Code Monkey home page Code Monkey logo

Comments (15)

dothebart avatar dothebart commented on August 29, 2024 1

@sajeevpr you may also be interested in https://groups.google.com/forum/#!topic/arangodb/fg7OoRW8Ltc - If you like it, @virmundi will probably appreciate feedback.

from arangodb-java-driver.

mvollmary avatar mvollmary commented on August 29, 2024

Hi Sajeev,

we have some test-code that could help you:
https://github.com/arangodb/arangodb-java-driver/blob/master/src/test/java/com/arangodb/ArangoDriverImportTest.java

Please, feel free to join our slack-community.
https://slack.arangodb.com/

Regards,
Mark

from arangodb-java-driver.

sajeevpr avatar sajeevpr commented on August 29, 2024

Thank you for the docs.

But I tried the following scenario.

  1. updated one doc. I was able to see the document updated using GUI.
  2. Deleted the same doc manually from the GUI
  3. inserted the same doc using java import api

But I am unable to see the document in GUI or using AQL.

So what could be the problem here.

I am seeing more dead documents after using import api.

But when I accessed like below, the document shows up.

http://:/_db/_system/_admin/aardvark/index.html#collection/Accounts/2293446076

I am using the code like below

ImportOptions options = new ImportOptions();
options.setOnDuplicate(OnDuplicate.REPLACE);
ImportResultEntity result = driver.importDocumentsByHeaderValues("Accounts", accountListForGraphDB,options);

Regards,
Sajeev

from arangodb-java-driver.

dothebart avatar dothebart commented on August 29, 2024

Hi Sajeev,
we would need a bit better to reproduce sequence in order to reproduce this.
We tried using arangosh + the webinterface: (we also tried java, however there should be no difference in the end)

db._create('test')
db.test.save({'_key': 'foo' , 'bla': 'bar'})

go into the collection tab, click test, document there; delete it in the webinterface.

db.test.save({'_key': 'foo' , 'bla': 'bar'})

press F5 in the browser, foo back again.

db._query('UPDATE "foo" WITH { blarg: "blub"} IN test')

delete in the browser

db.test.save({'_key': 'foo' , 'bla': 'bar'})

press F5 in the browser, foo back again

Any better hints how to reproduce this?

from arangodb-java-driver.

sajeevpr avatar sajeevpr commented on August 29, 2024

@dothebart , The issue is coming when I tried using the import api given in the java driver.

ImportResultEntity result = driver.importDocumentsByHeaderValues("Accounts", accountListForGraphDB,options);

Regards,
Sajeev

from arangodb-java-driver.

sajeevpr avatar sajeevpr commented on August 29, 2024

But updateDocument and createDocument given in the java driver is working perfectly. In this case, I need to put all my documents in a loop, then do a check whether the document exists or not and then do an insert or update.

from arangodb-java-driver.

sajeevpr avatar sajeevpr commented on August 29, 2024

The sequence is like this.
update document A
Delete document A
Insert document A
Query document A - This fails

from arangodb-java-driver.

mvollmary avatar mvollmary commented on August 29, 2024

Hi Sajeev,
I wrote a little test for your case. In my environment It runs without failures. Can you tell me, what I have to do, so that it fails?

package com.arangodb;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;

import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import com.arangodb.entity.DocumentEntity;
import com.arangodb.util.ImportOptions;
import com.arangodb.util.MapBuilder;

public class ImportDocumentTest {

    private static final String COLLECTION_NAME = "test";
    private static final String KEY = "foo";
    private static ArangoConfigure configure;
    private static ArangoDriver driver;

    @BeforeClass
    public static void setup() {
        configure = new ArangoConfigure();
        configure.init();
        driver = new ArangoDriver(configure);

        try {
            driver.deleteCollection(COLLECTION_NAME);
        } catch (final ArangoException e) {
        }
        try {
            driver.createCollection(COLLECTION_NAME);
        } catch (final ArangoException e) {
        }
    }

    @AfterClass
    public static void cleanup() {
        try {
            driver.deleteCollection(COLLECTION_NAME);
        } catch (final ArangoException e) {
        }
        configure.shutdown();
    }

    @SuppressWarnings("rawtypes")
    @Test
    public void process() throws ArangoException {
        // initial create the document
        driver.createDocument(COLLECTION_NAME, new MapBuilder().put("_key", KEY).put("bla", "bar").get());

        // update the document
        driver.updateDocument(COLLECTION_NAME + "/" + KEY, new MapBuilder().put("blarg", "blub").get());

        // delete the document
        driver.deleteDocument(COLLECTION_NAME + "/" + KEY);

        // import same document
        final ImportOptions options = new ImportOptions();
        final Collection<Collection<?>> headerValues = new ArrayList<Collection<?>>();
        headerValues.add(Arrays.asList("_key", "bla", "blarg"));
        headerValues.add(Arrays.asList(KEY, "bar", "blub"));
        driver.importDocumentsByHeaderValues(COLLECTION_NAME, headerValues, options);

        // get the document
        final DocumentEntity<Map> doc = driver.getDocument(COLLECTION_NAME + "/" + KEY, Map.class);
        Assert.assertFalse(doc.isError());
        Assert.assertEquals(COLLECTION_NAME + "/" + KEY, doc.getDocumentHandle());
        Assert.assertEquals("bar", doc.getEntity().get("bla"));
        Assert.assertEquals("blub", doc.getEntity().get("blarg"));

        // query the document via AQL
        final String query = "RETURN DOCUMENT(@docHandle)";
        final Map<String, Object> bindVars = new MapBuilder().put("docHandle", COLLECTION_NAME + "/" + KEY).get();
        final DocumentCursor<Map> result = driver.executeDocumentQuery(query, bindVars, null, Map.class);
        final DocumentEntity<Map> uniqueResult = result.getUniqueResult();
        Assert.assertNotNull(uniqueResult);
        Assert.assertEquals(COLLECTION_NAME + "/" + KEY, uniqueResult.getDocumentHandle());
        Assert.assertEquals("bar", uniqueResult.getEntity().get("bla"));
        Assert.assertEquals("blub", uniqueResult.getEntity().get("blarg"));
    }

}

from arangodb-java-driver.

sajeevpr avatar sajeevpr commented on August 29, 2024

Hi @mpv1989 ,
This code is working for me as well. Let me dig little deeper.

One thing I noted was after adding one document to the collection, I can see the Alive and dead objects both as 0. What does this mean?

Regards,
Sajeev

from arangodb-java-driver.

sajeevpr avatar sajeevpr commented on August 29, 2024

Hi @mpv1989 ,
Apologies, the issue was not there.
I mistakenly used String data type for indexing the document and then queried it like integer.

Its working now, when I index as Object data type for all fields.

Thank you for your time.

Regards,
Sajeev

from arangodb-java-driver.

mvollmary avatar mvollmary commented on August 29, 2024

can you modify my example, so it reproduces the pitfall you steped in?

from arangodb-java-driver.

sajeevpr avatar sajeevpr commented on August 29, 2024

@mpv1989 , I didn't exactly followed your program. Please find below the snippet which can explain the problem.

//Updating the document
        List<List<?>> values = new ArrayList<List<?>>();
        values.add(Arrays.asList("_key","firstName", "lastName", "age", "gender"));
        values.add(Arrays.asList("test1","Joe", "Public", 42, "male", 10)); // error
        values.add(Arrays.asList("test2","Jane", "Doe", 31, "female"));

        ImportOptions options = new ImportOptions();
        options.setOnDuplicate(OnDuplicate.UPDATE);

        final ImportResultEntity result = driver.importDocumentsByHeaderValues(UT_IMPORT_TEST, values,options);

        //Updating the same document with age given as string

        List<List<?>> values = new ArrayList<List<?>>();
        values.add(Arrays.asList("_key","firstName", "lastName", "age", "gender"));
        values.add(Arrays.asList("test1","Joe", "Public", "42", "male", 10)); // error
        values.add(Arrays.asList("test2","Jane", "Doe", "31", "female"));

        //Query age as just 42 or 32 will show no records, but document will come up if we query with "42" or "32"

from arangodb-java-driver.

mvollmary avatar mvollmary commented on August 29, 2024

thank you.

from arangodb-java-driver.

mvollmary avatar mvollmary commented on August 29, 2024

when you import documents, you can check if there was an error at one of them. With getErrors() In the ImportResultEntity you can find the number of documents where an error happend via importing.

from arangodb-java-driver.

sajeevpr avatar sajeevpr commented on August 29, 2024

ok. Thank you. I have incorporated that.

from arangodb-java-driver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.