public static GSONSchema configToSchema()

in gremlin/neptune-social-media-utils/src/main/java/com/aws/neptune/utils/generator/GSONUtil.java [99:210]


    public static GSONSchema configToSchema(String csvConfPath){
        GSONSchema gsonschema = new GSONSchema();
        CSVConfig csvConf = CSVGenerator.loadConfig(csvConfPath);

        //manually add node_id as a unique propertyKey and index
        PropertyKeyBean nodeIdKey = new PropertyKeyBean("node_id", "Integer");
        gsonschema.propertyKeys.add(nodeIdKey);
        IndexBean nodeIdIndex = new IndexBean(
                                    "node_id_comp",
                                    Arrays.asList("node_id"),
                                    true,
                                    true,
                                    null,
                                    null);
        gsonschema.vertexIndexes.add(nodeIdIndex);

        //Extract columns under VertexTypes from csv config and add to propertyKeys
        for (VertexTypeBean type : csvConf.VertexTypes){
            //add vertexLabels
            VertexLabelBean vertexLabel = new VertexLabelBean(type.name);
            gsonschema.vertexLabels.add(vertexLabel);

            //add propertyKeys
            for (Entry<String,ColumnBean> col : type.columns.entrySet()){
                String propertyKeyName = col.getKey();
                String propertyKeyType = col.getValue().dataType;
                boolean compositIndex = col.getValue().composit;
                String indexOnly = col.getValue().indexOnly;
                String mixedIndex = col.getValue().mixedIndex;

                //test key does not exist before adding
                if (null == gsonschema.getPropertyKey(propertyKeyName)) {
                    gsonschema.propertyKeys.add(
                            new PropertyKeyBean(propertyKeyName,propertyKeyType));
                }

                //add composit vertex indexes if any
                if(compositIndex == true) {
                    IndexBean index = new IndexBean(
                                        String.join("_", propertyKeyName, "comp"),
                                        Arrays.asList(propertyKeyName),
                                        compositIndex,
                                        false,
                                        indexOnly,
                                        null);
                    if (null == gsonschema.getVertexIndex(index.name)) {
                        gsonschema.vertexIndexes.add(index);
                    }
                }
                //add mixed vertex index if any
                if(mixedIndex != null) {
                    IndexBean index = new IndexBean(
                                        String.join("_", propertyKeyName, "mixed"),
                                        Arrays.asList(propertyKeyName),
                                        false,
                                        false,
                                        indexOnly,
                                        mixedIndex);
                    if (null == gsonschema.getVertexIndex(index.name)) {
                        gsonschema.vertexIndexes.add(index);
                    }
                }
            }
        }

        //extract edge properties from csv config and add to propertyKeys
        for (EdgeTypeBean type : csvConf.EdgeTypes){
            EdgeLabelBean edgeLabel = new EdgeLabelBean(type.name, type.multiplicity);
            gsonschema.edgeLabels.add(edgeLabel);
            if (type.columns != null) {
                //extract columns and add to propertKeys
                for (Entry<String, ColumnBean> col : type.columns.entrySet()) {
                    String propertyKeyName = col.getKey();
                    String propertyKeyType = col.getValue().dataType;
                    boolean compositIndex = col.getValue().composit;
                    String indexOnly = col.getValue().indexOnly;
                    String mixedIndex = col.getValue().mixedIndex;
                    gsonschema.propertyKeys.add(new PropertyKeyBean(
                                                        propertyKeyName,
                                                        propertyKeyType));

                    //add composit edgeIndex if any
                    if (compositIndex == true) {
                        IndexBean index = new IndexBean(
                                              String.join("_", propertyKeyName, "comp"),
                                              Arrays.asList(propertyKeyName),
                                              compositIndex,
                                              false,
                                              indexOnly,
                                              mixedIndex);
                        if (null == gsonschema.getEdgeIndex(index.name)) {
                            gsonschema.edgeIndexes.add(index);
                        }
                    }
                    //add mixed edgeIndex if any
                    if(mixedIndex != null) {
                        IndexBean index = new IndexBean(
                                            String.join("_", propertyKeyName, "mixed"),
                                            Arrays.asList(propertyKeyName),
                                            false,
                                            false,
                                            indexOnly,
                                            mixedIndex);
                        if (null == gsonschema.getEdgeIndex(index.name)) {
                            gsonschema.edgeIndexes.add(index);
                        }
                    }
                }
            }
        }
        return gsonschema;
    }