21.6 Before Using the Converter (1): Create Database Document Sets
Before using the JSON-to-duality converter you need to create
JSON
-type document sets in Oracle Database from the original external
document sets. The input to the converter for each set of documents is an Oracle Database
table with a single column of JSON
data type.
You can export JSON document sets from a document database and import them
into JSON
-type columns using various tools provided by Oracle and
document databases. (MongoDB command-line tools mongoexport
and
mongoimport
provide one way to do this.)
We assume that each of the student, teacher, and course document sets has
been thus loaded into a JSON
-type column, data
, of a
temporary transfer table (e.g. course_tab
for
course documents) from a document-database dump file of documents of the given kind (e.g.
course documents). This is shown in the following example:
Example 21-4 Create an Oracle Document Set (Course) From a JSON Dump File.
This example creates an Oracle Database external table,
dataset_course
, from a JSON dump file of a set of course documents,
course.json
. It then creates temporary transfer table
course_tab
with JSON
-type column data. Finally, it
imports the course documents into temporary transfer table course_tab
,
which can be used as input to the JSON-relational converter.
The documents in course_tab.data
are those shown in the
example "Course Document Set (Migrator Input)" in School Administration Example, Migrator Input Documents.
(Similarly student and teacher document sets are loaded into transfer tables
student_tab
and teacher_tab
from external tables
dataset_student
and dataset_teacher
created from dump
files student.json
and teacher.json
, respectively.)
CREATE TABLE dataset_course (data JSON)
ORGANIZATION EXTERNAL
(TYPE ORACLE_BIGDATA
ACCESS PARAMETERS (com.oracle.bigdata.fileformat = jsondoc)
LOCATION (data_dir:'course.json'))
PARALLEL
REJECT LIMIT UNLIMITED;
CREATE TABLE course_tab AS SELECT * FROM dataset_course;
SELECT json_serialize(data PRETTY) FROM course_tab;
JSON_SERIALIZE(DATAPRETTY)
-----------------------------------
{
"courseId" : "MATH101",
"name" : "Algebra",
"creditHours" : 3,
"students" :
[
{
"studentId" : 1,
"name" : "Donald P."
},
{
"studentId" : 5,
"name" : "Hye E."
}
],
"teacher" :
{
"teacherId" : 101,
"name" : "Abdul J."
},
"Notes" : "Prerequisite for Advanced Algebra"
}
{
"courseId" : "MATH102",
"name" : "Calculus",
"creditHours" : 4,
"students" :
[
{
"studentId" : 2,
"name" : "Elena H."
},
{
"studentId" : 4,
"name" : "Georgia D."
},
{
"studentId" : 9,
"name" : "Luis F."
},
{
"studentId" : 10,
"name" : "Ming L."
}
],
"teacher" :
{
"teacherId" : 101,
"name" : "Abdul J."
}
}
{
"courseId" : "CS101",
"name" : "Algorithms",
"creditHours" : 5,
"students" :
[
{
"studentId" : 1,
"name" : "Donald P."
},
{
"studentId" : 2,
"name" : "Elena H."
},
{
"studentId" : 4,
"name" : "Georgia D."
},
{
"studentId" : 7,
"name" : "Jatin S."
},
{
"studentId" : 9,
"name" : "Luis F."
}
],
"teacher" :
{
"teacherId" : 102,
"name" : "Betty Z."
}
}
{
"courseId" : "CS102",
"name" : "Data Structures",
"creditHours" : 3,
"students" :
[
{
"studentId" : 1,
"name" : "Donald P."
},
{
"studentId" : 2,
"name" : "Elena H."
},
{
"studentId" : 5,
"name" : "Hye E."
},
{
"studentId" : 7,
"name" : "Jatin S."
},
{
"studentId" : 8,
"name" : "Katie H."
}
],
"teacher" :
{
"teacherId" : 102,
"name" : "Betty Z."
}
}
{
"courseId" : "MATH103",
"name" : "Advanced Algebra",
"creditHours" : "3",
"students" :
[
{
"studentId" : 3,
"name" : "Francis K."
},
{
"studentId" : 4,
"name" : "Georgia D."
},
{
"studentId" : 6,
"name" : "Ileana D."
},
{
"studentId" : 8,
"name" : "Katie H."
},
{
"studentId" : 9,
"name" : "Luis F."
}
],
"teacher" :
{
"teacherId" : 103,
"name" : "Colin J."
}
}
Note:
Oracle Database supports the use of textual JSON objects that
represent nonstandard-type scalar JSON values. For example, the extended
object
{"$numberDecimal" : 31}
represents a JSON scalar value of the nonstandard
type decimal number, and when interpreted as such it is replaced by a decimal
number in Oracle's native binary JSON format, OSON.
Some non-Oracle databases also use such extended objects. If such an external extended object is a format recognized by Oracle then, when the JSON data is loaded (ingested), the extended object is replaced by the corresponding Oracle scalar JSON value. If the format isn't supported by Oracle then the extended object is retained as such, that is, as an object.
See Textual JSON Objects That Represent Extended Scalar Values in Oracle Database JSON Developer’s Guide for information about Oracle support for extended objects.
See Also:
-
Migrate Application Data from MongoDB to Oracle Database in Oracle Database API for MongoDB for information about using commands
mongoexport
andmongoimport
to migrate -
Loading External JSON Data in Oracle Database JSON Developer’s Guide for loading data from a document-database dumpfile into Oracle Database
Parent topic: Migrating From JSON To Duality