@Override public boolean execute() throws Exception { if (_dimensions == null && _metrics == null && _timeColumnName == null) { LOGGER.error( "Error: Missing required argument, please specify at least one of -dimensions, -metrics, -timeColumnName"); return false; } Schema schema; if (_avroSchemaFile != null) { schema = AvroUtils.getPinotSchemaFromAvroSchemaFile(new File(_avroSchemaFile), buildFieldTypesMap(), _timeUnit); } else if (_avroDataFile != null) { schema = AvroUtils.getPinotSchemaFromAvroDataFile(new File(_avroDataFile), buildFieldTypesMap(), _timeUnit); } else { LOGGER.error("Error: Missing required argument, please specify either -avroSchemaFile, or -avroDataFile"); return false; } schema.setSchemaName(_pinotSchemaName); File outputDir = new File(_outputDir); if (!outputDir.isDirectory()) { LOGGER.error("ERROR: Output directory: %s does not exist or is not a directory", _outputDir); } File outputFile = new File(outputDir, _pinotSchemaName + ".json"); LOGGER.info("Store Pinot schema to file: {}", outputFile.getAbsolutePath()); try (FileWriter writer = new FileWriter(outputFile)) { writer.write(schema.toString()); } return true; }
job.getConfiguration().set(JobConfigConstants.SCHEMA, _dataSchema.toString());
PostMethod httpPost = new PostMethod(url.toString()); try { Part[] parts = {new StringPart(schema.getSchemaName(), schema.toString())}; MultipartRequestEntity requestEntity = new MultipartRequestEntity(parts, new HttpMethodParams()); httpPost.setRequestEntity(requestEntity);
Schema schema = createDummySchema(schemaName); String url = _controllerRequestURLBuilder.forSchemaCreate(); PostMethod postMethod = sendMultipartPostRequest(url, schema.toString()); Assert.assertEquals(postMethod.getStatusCode(), 200); postMethod = sendMultipartPostRequest(url, schema.toString()); Assert.assertEquals(postMethod.getStatusCode(), 200); Schema inputSchema = Schema.fromString(schema.toString()); Assert.assertEquals(readSchema, inputSchema); Assert.assertTrue(readSchema.getFieldSpecMap().containsKey("NewColumn")); schema.addField(new DimensionFieldSpec(yetAnotherColumn, FieldSpec.DataType.STRING, true)); PutMethod putMethod = sendMultipartPutRequest(_controllerRequestURLBuilder.forSchemaUpdate(schemaName), schema.toString()); Assert.assertEquals(putMethod.getStatusCode(), 200); inputSchema = Schema.fromString(schema.toString()); Assert.assertEquals(readSchema, inputSchema); Assert.assertTrue(readSchema.getFieldSpecMap().containsKey(yetAnotherColumn)); schema.toString().substring(1)); putMethod = sendMultipartPutRequest(_controllerRequestURLBuilder.forSchemaUpdate(schemaName), schema.toString()); Assert.assertEquals(putMethod.getStatusCode(), 400);