Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.project
.classpath
.checkstyle
.settings/
.idea/
*.log
*.lck
*.iml
target/
*.DS_Store
*.patch
*~
git.properties
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions Sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from entity.document.Document import Document
from entity.document.DocumentStore import DocumentStore
from entity.storage.ConnectionManager import ConnectionManager
from entity.storage.Connection import Connection


"""Example for customer may works with Python client"""
"""Create a connection, get store, insert new document into store"""
# create a connection by path:user@password
connection = Connection(ConnectionManager.get_connection(url="ojai:mapr:user@password"))

# Get a store and keep it as DocumentStore object
store = DocumentStore(connection.get_store(store_name="/test_name"))

# Json string or json map
json_string = "json string"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a valid JSON Document String, something like

{"name": "Joe", "age": 50, "address": {"street": "555 Moon Way", "city": "Gotham"}}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed


# Create new document from json_document
new_document = connection.new_document(json_string)

# Insert new document into the store
store.insert_or_replace(new_document)

# close
store.close()
connection.close()


"""Create a connection, get store, find document by id"""
# create a connection by path:user@password
connection = Connection(ConnectionManager.get_connection(url="ojai:mapr:user@password"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am going to update the functional spec with the new URL format, please update the example with a matching format.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean that its must looks like
connection = Connection(ConnectionManager.get_connection(url="hostname:port")) and user@password is not required for connection?


# Get a store and keep it as DocumentStore object
store = DocumentStore(connection.get_store(store_name="/test_name"))

# Fetch document from store by id
json_document = store.find_by_id("id_005")

# close
store.close()
connection.close()


"""Create a connection, get store, create a query, execute find query and got through document stream"""
# create a connection by path:user@password
connection = Connection(ConnectionManager.get_connection(url="ojai:mapr:user@password"))

# Get a store and keep it as DocumentStore object
store = DocumentStore(connection.get_store(store_name="/test_name"))

# Build query
query = connection.new_query().select("_id", "city").build()

# fetch all document from store by query
document_stream = store.find_query(query)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to wrap the return value in the constructor like above in case of Connection and DocumentStore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the find_query method creates a constructor within itself


# go to fetched records and pritnt them
for document in document_stream.result:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the result method defined? I see an iterator() defined in the DocumentStream class.

print document


# close
store.close()
connection.close()



Empty file added entity/Table.py
Empty file.
169 changes: 169 additions & 0 deletions entity/document/Document.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
from abc import ABCMeta, abstractmethod


class Document:
__metaclass__ = ABCMeta

@abstractmethod
def set_id(self, _id):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this single method accept both binary and string types as "_id" value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, here will check which _id type was given

raise NotImplementedError("Should have implemented this")

@abstractmethod
def get_id(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this return Value type? Is there a way to annotate the return type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raise NotImplementedError("Should have implemented this")

@abstractmethod
def get_id_string(self):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def get_id_binary(self):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def size(self):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def empty(self):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def set(self, field_path, value):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to above declaration, if this method is supposed to pass a Value type, let's call it set_value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method should work not only with Value, we check value param type in the method and delegate another method according to value type
https://github.com/mapr/private-ojai/blob/branch-2.0.1/core/src/main/java/org/ojai/Document.java#L108-L500

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the Document abstract class we already have a method for each type, like set_time, set_map, set_document. So we can remove just set() method, or use it as a main method which will callable.

raise NotImplementedError("Should have implemented this")

@abstractmethod
def set_boolean(self, field_path, value):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def set_byte(self, field_path, value):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def set_long(self, field_path, value):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def set_float(self, field_path, value):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def set_decimal(self, field_path, value):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def set_time(self, field_path, value):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def set_date(self, field_path, value):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def set_timestamp(self, field_path, value):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def set_interval(self, field_path, value):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def set_byte_array(self, field_path, value, offset=None, length=None):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def set_map(self, field_path, value):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def set_document(self, field_path, value):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def set_value_obj(self, field_path, value):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def set_array(self, field_path, values):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def set_null(self, field_path):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def delete(self, field_path):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def get_string(self, field_path):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def get_boolean(self, field_path):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def get_byte(self, field_path):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def get_int(self, field_path):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def get_long(self, field_path):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def get_float(self, field_path):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def get_double(self, field_path):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def get_decimal(self, field_path):
raise NotImplementedError("Should have implemented this")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note that Decimal and Interval types are not supported in MapR-DB yet. The implementation of these methods should throw "Unsupported Error/Exception"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure


@abstractmethod
def get_time(self, field_path):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def get_date(self, field_path):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def get_timestamp(self, field_path):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def get_binary(self, field_path):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def get_interval(self, field_path):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def get_value(self, field_path):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def get_map(self, field_path):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def get_list(self, field_path):
raise NotImplementedError("Should have implemented this")

@abstractmethod
def as_reader(self, field_path=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we won't implement DocumentReader interface in the first release, let's not have this method in the abstract class yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

raise NotImplementedError("Should have implemented this")

@abstractmethod
def as_map(self):
raise NotImplementedError("Should have implemented this")
Loading