Package com.socrata.model.importer

Examples of com.socrata.model.importer.Column


                    "}}";
   
    @Test
    public void testSerializationCompleteColumn() throws Exception
    {
        Column col =  mapper.readValue(JSON_COMPLETE, Column.class);
        TestCase.assertNotNull(col);
        TestCase.assertEquals(col.getId(), (Integer) 1414729);
        TestCase.assertEquals(col.getPosition(), 1);
        TestCase.assertEquals(col.getWidth(), (Integer) 100);
        TestCase.assertEquals(col.getName(), "col1");
        TestCase.assertEquals(col.getFieldName(), "col1");
        TestCase.assertEquals(col.getDataTypeName(), "number");
        TestCase.assertEquals(col.getRenderTypeName(), "number");
        TestCase.assertEquals(col.getFormat().get("mask"), "##-##-##");
        TestCase.assertEquals(col.getFormat().get("precisionStyle"), "standard");
        TestCase.assertEquals(col.getFormat().get("align"), "left");
        TestCase.assertEquals(col.getFormat().get("noCommas"), "true");

        String roundTripJson = mapper.writeValueAsString(col);
        TestCase.assertEquals(roundTripJson, JSON_COMPLETE);
    }
View Full Code Here


    }

    @Test
    public void testSerializationIncompleteColumn() throws Exception
    {
        Column col =  mapper.readValue(JSON_INCOMPLETE, Column.class);
        TestCase.assertNotNull(col);
        TestCase.assertNull(col.getId());
        TestCase.assertEquals(col.getPosition(), 1);
        TestCase.assertEquals(col.getWidth(), (Integer) 100);
        TestCase.assertEquals(col.getName(), "col1");
        TestCase.assertEquals(col.getFieldName(), "col1");
        TestCase.assertEquals(col.getDataTypeName(), "number");
        TestCase.assertNull(col.getRenderTypeName());
        TestCase.assertNull(col.getFormat());
    }
View Full Code Here

    }

    @Test
    public void testSerializationOvercompleteColumn() throws Exception
    {
        Column col =  mapper.readValue(JSON_OVERCOMPLETE, Column.class);
        TestCase.assertNotNull(col);
        TestCase.assertEquals(col.getId(), (Integer) 1414729);
        TestCase.assertEquals(col.getPosition(), 1);
        TestCase.assertEquals(col.getWidth(), (Integer) 100);
        TestCase.assertEquals(col.getName(), "col1");
        TestCase.assertEquals(col.getFieldName(), "col1");
        TestCase.assertEquals(col.getDataTypeName(), "number");
        TestCase.assertEquals(col.getRenderTypeName(), "number");
        TestCase.assertEquals(col.getFormat().get("mask"), "##-##-##");
        TestCase.assertEquals(col.getFormat().get("precisionStyle"), "standard");
        TestCase.assertEquals(col.getFormat().get("align"), "left");
        TestCase.assertEquals(col.getFormat().get("noCommas"), "true");
    }
View Full Code Here

     public static void adaptSchemaForAggregates(Dataset schema) {
        // TODO: give users the option to choose a new resource name; in the meanwhile, it can be set after the job completes
        schema.setResourceName(null);
        List<Column> columns = schema.getColumns();
        for (int i = 0; i < columns.size(); i++) {
            Column col = columns.get(i);
            if (col != null) {
                Map<String, String> format = col.getFormat();
                if (format != null) {
                    String aggregation = format.remove(groupingKey);
                    format.remove(drillingKey);
                    if (aggregation != null) {
                        String oldFieldName = col.getFieldName();
                        col.setFieldName(aggregation + "_" + oldFieldName);
                    }
                }
            }
        }
    }
View Full Code Here

    /**
     * Retruns the field name of the row identifier, if there is one, else null
     */
    public static String getRowIdentifierName(Dataset schema) {
        Column rowIdentifierColumn = schema.lookupRowIdentifierColumn();
        if (rowIdentifierColumn == null) {
            return null;
        } else {
            return rowIdentifierColumn.getFieldName();
        }
    }
View Full Code Here

        return publishViaSoda2(producer, ddl, PublishMethod.replace, id, file, 0, containsHeaderRow);
    }

    private static String getDatasetRowId(SodaDdl ddl, String id) throws SodaError, InterruptedException {
        Dataset info = (Dataset) ddl.loadDatasetInfo(id);
        Column rowIdentifier = info.lookupRowIdentifierColumn();
        String rowIdentifierName;
        if (rowIdentifier == null) {
            rowIdentifierName = ":id";
        } else {
            rowIdentifierName = rowIdentifier.getFieldName();
        }
        return rowIdentifierName;
    }
View Full Code Here

    public void testSchemaAdaptation() {
        // set up original dataset schema
        String groupingKey = "grouping_aggregate";
        Dataset schema = new Dataset();

        Column colNoFormatting = new Column();
        colNoFormatting.setFieldName("col_without_formatting");

        Column colIgnorableFormatting = new Column();
        colIgnorableFormatting.setFieldName("col_with_ignorable_formatting");
        Map<String, String> ignorableFormatting = new HashMap<String,String>();
        ignorableFormatting.put("drill_down", "true");
        colIgnorableFormatting.setFormat(ignorableFormatting);

        Column colAggregatedFormatting = new Column();
        colAggregatedFormatting.setFieldName("col_with_aggregated_formatting");
        Map<String, String> aggregateFormatting = new HashMap<String,String>();
        aggregateFormatting.put(groupingKey, "count");
        colAggregatedFormatting.setFormat(aggregateFormatting);

        List<Column> columns = new ArrayList<Column>();
        columns.add(colNoFormatting);
        columns.add(colIgnorableFormatting);
        columns.add(colAggregatedFormatting);
        schema.setColumns(columns);

        // edit schema
        PortUtility.adaptSchemaForAggregates(schema);

        // test that edits are as expected
        List<Column> editedColumns = schema.getColumns();
        Column col1 = editedColumns.get(0);
        Column col2 = editedColumns.get(1);
        Column col3 = editedColumns.get(2);

        TestCase.assertNotNull(col1);
        TestCase.assertNotNull(col2);
        TestCase.assertNotNull(col3);

        // columns without formatting should be left alone
        TestCase.assertEquals(colNoFormatting, col1);

        // columns with ignorable formatting should be left alone
        TestCase.assertEquals(colIgnorableFormatting, col2);

        // columns with aggregation info in the formatting should have the aggregation info removed
        // and prepended to the field name:
        TestCase.assertFalse(col3.getFormat().containsKey(groupingKey));
        TestCase.assertEquals("count_col_with_aggregated_formatting", col3.getFieldName());
    }
View Full Code Here

TOP

Related Classes of com.socrata.model.importer.Column

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.