__init__(self,
jsonSource,
destination,
outputFormat=0,
schemaHints={},
jsonParserInstance=None,
loggingLevel=30,
logFile=None)
(Constructor)
| source code
|
Create a JSON-to-Relation converter. The JSON source can be a file
with JSON objects, a StringIO.StringIO string pseudo file, stdin, or a
MongoDB
The destination can be a file, where CSV is written in Excel-readable
form, stdout, or a MySQL table specification, where the ouput rows will
be inserted.
SchemaHints optionally specify the SQL types of particular columns. By
default the processJSONObs() method will be conservative, and specify
numeric columns as DOUBLE. Even though all encountered values for one
column could be examined, and a more appropriate type chosen, such as INT
when only 4-byte integers are ever seen, future additions to the table
might exceed the INT capacity for that column. Example
If schemaHints is provided, it is a Dict mapping column names to
ColDataType. The column names in schemaHints must match the corresponding
(fully nested) key names in the JSON objects:
schemaHints dict: {'msg.length' : ColDataType.INT,
'chunkSize' : ColDataType.INT}
For unit testing isolated methods in this class, set jsonSource and
destination to None.
- Parameters:
jsonSource ({InPipe | InString | InURI | InMongoDB}) - subclass of InputSource that wraps containing JSON structures, or
a URL to such a source
destination ({OutputPipe | OutputFile | OutputMySQLTable}) - instruction to were resulting rows are to be directed
outputFormat (OutputFormat) - format of output. Can be CSV or SQL INSERT statements
schemaHints (Map<String,ColDataTYpe>) - Dict mapping col names to data types (optional)
jsonParserInstance ({GenericJSONParser | EdXTrackLogJSONParser |
CourseraTrackLogJSONParser}) - a parser that takes one JSON string, and returns a CSV row.
Parser also must inform this parent object of any generated
column names.
loggingLevel ({logging.DEBUG | logging.WARN | logging.INFO | logging.ERROR |
logging.CRITICAL}) - level at which logging output is show.
- Raises:
ValueErrer - when value of jsonParserInstance is neither None, nor an instance
of GenericJSONParser, nor one of its subclasses.
ValueError - when jsonSource is not an instance of InPipe, InString, InURI, or
InMongoDB
- Overrides:
object.__init__
|