|
1 | 1 | import os |
| 2 | +import ujson |
2 | 3 |
|
3 | 4 | import future.utils |
4 | 5 |
|
@@ -307,7 +308,7 @@ def put_item(self, |
307 | 308 | locals()) |
308 | 309 |
|
309 | 310 | def put_items(self, container, path, items, access_key=None, raise_for_status=None, condition=None): |
310 | | - """A helper to put several items, calling put_item for each. |
| 311 | + """[OBSOLETED] A helper to put several items, calling put_item for each. |
311 | 312 |
|
312 | 313 | Parameters |
313 | 314 | ---------- |
@@ -786,9 +787,78 @@ def get_records(self, |
786 | 787 | locals(), |
787 | 788 | v3io.dataplane.output.GetRecordsOutput) |
788 | 789 |
|
| 790 | + # |
| 791 | + # Helpers |
| 792 | + # |
| 793 | + |
| 794 | + def create_schema(self, |
| 795 | + container, |
| 796 | + path, |
| 797 | + access_key=None, |
| 798 | + raise_for_status=None, |
| 799 | + transport_actions=None, |
| 800 | + key=None, |
| 801 | + fields=None): |
| 802 | + """Creates a KV schema file |
| 803 | +
|
| 804 | + Parameters |
| 805 | + ---------- |
| 806 | + container (Required) : str |
| 807 | + The container on which to operate. |
| 808 | + path (Required) : str |
| 809 | + The path of the object |
| 810 | + access_key (Optional) : str |
| 811 | + The access key with which to authenticate. Defaults to the V3IO_ACCESS_KEY env. |
| 812 | + key (Required) : str |
| 813 | + The key field name |
| 814 | + fields (Required) : list of dicts |
| 815 | + A dictionary of fields, where each item has: |
| 816 | + - name (string) |
| 817 | + - type (string - one of string, double, long) |
| 818 | + - nullable (boolean) |
| 819 | +
|
| 820 | + Example: [ |
| 821 | + { |
| 822 | + 'name': 'my_field', |
| 823 | + 'type': 'string', |
| 824 | + 'nullable': False |
| 825 | + }, |
| 826 | + { |
| 827 | + 'name': 'who', |
| 828 | + 'type': 'string', |
| 829 | + "nullable": True |
| 830 | + } |
| 831 | + ] |
| 832 | +
|
| 833 | + Return Value |
| 834 | + ---------- |
| 835 | + A `Response` object |
| 836 | + """ |
| 837 | + put_object_args = locals() |
| 838 | + put_object_args['path'] = os.path.join(put_object_args['path'], '.%23schema') |
| 839 | + put_object_args['offset'] = 0 |
| 840 | + put_object_args['body'] = self._get_schema_contents(key, fields) |
| 841 | + del(put_object_args['key']) |
| 842 | + del (put_object_args['fields']) |
| 843 | + |
| 844 | + return self._transport.request(container, |
| 845 | + access_key or self._access_key, |
| 846 | + raise_for_status, |
| 847 | + transport_actions, |
| 848 | + v3io.dataplane.request.encode_put_object, |
| 849 | + put_object_args) |
| 850 | + |
789 | 851 | @staticmethod |
790 | 852 | def _normalize_stream_path(path): |
791 | 853 | if not path.endswith('/'): |
792 | 854 | return path + '/' |
793 | 855 |
|
794 | 856 | return path |
| 857 | + |
| 858 | + @staticmethod |
| 859 | + def _get_schema_contents(key, fields): |
| 860 | + return ujson.dumps({ |
| 861 | + 'hashingBucketNum': 0, |
| 862 | + 'key': key, |
| 863 | + 'fields': fields |
| 864 | + }) |
0 commit comments