Package com.asakusafw.directio.hive.common

Examples of com.asakusafw.directio.hive.common.HiveTableInfo


     * @param statement the source statement
     * @param writer the target writer
     * @throws IOException if failed by I/O error
     */
    public static void emit(HiveCreateTable statement, Appendable writer) throws IOException {
        HiveTableInfo table = statement.getTableInfo();
        Context c = new Context(writer);

        emitCreateTableHead(c, statement);

        // TODO PARTITIONED BY
        // TODO CLUSTERED BY
        // TODO SKEWED BY

        RowFormatInfo rowFormat = table.getRowFormat();
        if (rowFormat != null) {
            switch (rowFormat.getKind()) {
            case DELIMITED:
                emitDelimitedRowFormat(c, (DelimitedRowFormatInfo) table.getRowFormat());
                break;
            case SERDE:
                throw new UnsupportedOperationException("ROW FORMAT SERDE");
            default:
                throw new AssertionError(rowFormat.getKind());
            }
        }
        if (table.getFormatName() != null) {
            c.tokens("STORED", "AS");
            c.token(table.getFormatName());
            c.newLine();
        }
        // or TODO STORED BY

        if (statement.getLocation() != null) {
            c.token("LOCATION");
            c.string(statement.getLocation());
            c.newLine();
        }
        if (table.getTableProperties().isEmpty() == false) {
            c.token("TBLPROPERTIES");
            c.token("(");
            c.newLine();
            c.indent(+1);
            emitProperties(c, table.getTableProperties());
            c.indent(-1);
            c.token(")");
            c.newLine();
        }
    }
View Full Code Here


        c.token("TABLE");
        if (statement.isSkipPresentTable()) {
            c.tokens("IF", "NOT", "EXISTS");
        }

        HiveTableInfo table = statement.getTableInfo();
        if (statement.getDatabaseName() == null) {
            c.name(table.getTableName());
        } else {
            c.name(String.format("%s.%s", statement.getDatabaseName(), table.getTableName()));
        }

        c.token("(");
        c.newLine();
        c.indent(+1);
        HiveFieldInfo[] fields = table.getFields().toArray(new HiveFieldInfo[table.getFields().size()]);
        for (int i = 0; i < fields.length; i++) {
            HiveFieldInfo field = fields[i];
            c.name(field.getFieldName());
            c.token(field.getFieldTypeInfo().getQualifiedName());
            if (field.getFieldComment() != null) {
                c.token("COMMENT");
                c.string(field.getFieldComment());
            }
            if (i != fields.length - 1) {
                c.token(",");
            }
            c.newLine();
        }
        c.indent(-1);
        c.token(")");
        c.newLine();

        if (table.getTableComment() != null) {
            c.token("COMMENT");
            c.string(table.getTableComment());
            c.newLine();
        }
    }
View Full Code Here

        }
        int count = 0;
        Writer writer = open(configuration);
        try {
            for (Class<?> aClass : collector.getClasses()) {
                HiveTableInfo table;
                try {
                    table = aClass.asSubclass(HiveTableInfo.class).newInstance();
                } catch (Exception e) {
                    LOG.warn(MessageFormat.format(
                            "Failed to instantiate: {0}",
                            aClass.getName()), e);
                    continue;
                }
                LOG.info(MessageFormat.format(
                        "Generating DDL for {0}",
                        table.getTableName()));
                HiveQlEmitter.emit(new Ql(table, configuration), writer);
                writer.write(STATEMENT_SEPARATOR);
                count++;
            }
        } finally {
View Full Code Here

                }
                if (Modifier.isAbstract(aClass.getModifiers())) {
                    return false;
                }
                if (pattern != null) {
                    HiveTableInfo info;
                    try {
                        info = aClass.asSubclass(HiveTableInfo.class).newInstance();
                    } catch (Exception e) {
                        LOG.warn(MessageFormat.format(
                                "Failed to instantiate: {0}",
                                aClass.getName()), e);
                        return false;
                    }
                    if (pattern.matcher(info.getTableName()).matches() == false) {
                        LOG.debug("Filtered table: {}", info.getTableName());
                        return false;
                    }
                }
                return true;
            }
View Full Code Here

        HiveTable table = descriptor.getDataModelClass().getAnnotation(HiveTable.class);
        assertThat(table, is(notNullValue()));
        Class<? extends HiveTableInfo>[] infos = table.value();
        assertThat(infos, arrayWithSize(1));
        HiveTableInfo info = infos[0].newInstance();
        assertThat(info.getTableName(), is("model"));

        Method simple = descriptor.getDataModelClass().getMethod("getSimpleOption");
        HiveField field = simple.getAnnotation(HiveField.class);
        assertThat(field, is(notNullValue()));
        assertThat(field.name(), is("simple"));
View Full Code Here

TOP

Related Classes of com.asakusafw.directio.hive.common.HiveTableInfo

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.