schemacrawler / SchemaCrawler

Free database schema discovery and comprehension tool
http://www.schemacrawler.com/
Other
1.6k stars 199 forks source link

support Phoenix ? #249

Closed zhanghuidouble closed 5 years ago

zhanghuidouble commented 5 years ago

Describe the solution you'd like A clear and concise description of what you want to happen.

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

zhanghuidouble commented 5 years ago

@schemacrawler Do you plan to support Phoenix datasource?

sualeh commented 5 years ago

Did you try to use SchemaCrawler with the Phoenix JDBC driver? SchemaCrawler supports any database with a conformant JDBC driver.

zhanghuidouble commented 5 years ago

Thanks ,I try with version 15.06.01, I can get All I wanted !

zhanghuidouble commented 5 years ago

sorry,I find that I can getTables(schema = "") and columns but I can not get Schema with version 15.06.01

after I check the code,I found the reason is

PhoenixDatabaseMetaData.supportsSchemasInTableDefinitions return false

so SchemaRetrievalOptionsBuilder.lookupSupportsSchemas return false

but I can getSchema with Metadata like

 Properties props = new Properties();

            props.setProperty(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, Boolean.toString(true));
            props.setProperty(QueryServices.IS_SYSTEM_TABLE_MAPPED_TO_NAMESPACE, Boolean.toString(true));
            // Connect to the database
            connection = DriverManager.getConnection("jdbc:phoenix:xx.xx.xx.xx", props);
            rs = connection.getMetaData().getSchemas();
            while (rs.next()) {
                String schemaName = rs.getString(1);
                System.out.println("getSchmea==>" + schemaName);
            }

Do you think you will support and fix it ?

zhanghuidouble commented 5 years ago

My code with SchemaCrawler is

Properties props = new Properties();

            props.setProperty(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, Boolean.toString(true));

            props.setProperty(QueryServices.IS_SYSTEM_TABLE_MAPPED_TO_NAMESPACE, Boolean.toString(true));
            String driver = "org.apache.phoenix.jdbc.PhoenixDriver";
            Class.forName(driver);
            // Connect to the database

            SchemaInfoLevel schemaInfoLevel = SchemaInfoLevelBuilder.builder().setRetrieveTableColumns(true).
                    setRetrieveTableDefinitionsInformation(true).setRetrieveAdditionalTableAttributes(true)
                    .setRetrieveColumnDataTypes(true).setRetrieveTables(true).setRetrievePrimaryKeyDefinitions(false)
                    .setRetrieveForeignKeys(false).setRetrieveDatabaseInfo(true).toOptions();
            final SchemaCrawlerOptionsBuilder schemaCrawlerOptionsBuilder = SchemaCrawlerOptionsBuilder
                    .builder()
                    .includeSchemas(new IncludeAll())
                    .includeTables(new IncludeAll())
                    .includeColumns(new IncludeAll())
                    .includeRoutines(new ExcludeAll())
                    .includeSequences(new ExcludeAll())
                    .noEmptyTables()
                    .grepOnlyMatching(true)
                    .withSchemaInfoLevel(schemaInfoLevel);

                     try (Connection connection = DriverManager.getConnection("jdbc:phoenix:xx .xx.xx.xx", props)) {
                Catalog simpleCatalog = SchemaCrawlerUtility.getCatalog(connection,
                                                                        schemaCrawlerOptionsBuilder.toOptions());

                Collection<Table> tables = simpleCatalog.getTables();

                tables.forEach(table -> {
                // table.getSchema is "" 
                    System.out.println("tables=>" + table);
                });

            }
sualeh commented 5 years ago

@zhanghuidouble I do not have the ability to set up and test Phoenix. It is quite simple to write a SchemaCrawler plugin that will support Phoenix. Please create a jar file using a project and code similar to the SchemaCrawler plugin for Oracle Times Ten.

zhanghuidouble commented 5 years ago

ok ,I will try ,thanks again!