Java Code Examples for org.apache.kylin.metadata.model.TableDesc#isView()

The following examples show how to use org.apache.kylin.metadata.model.TableDesc#isView() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModelDataGenerator.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private void generateCreateTableDDL(Set<TableDesc> tables, PrintWriter out) {
    for (TableDesc t : tables) {
        if (t.isView())
            continue;

        out.print("DROP TABLE IF EXISTS " + normHiveIdentifier(t.getIdentity()) + ";\n");

        out.print("CREATE TABLE " + normHiveIdentifier(t.getIdentity()) + "(" + "\n");

        for (int i = 0; i < t.getColumns().length; i++) {
            ColumnDesc col = t.getColumns()[i];
            out.print("    ");
            if (i > 0) {
                out.print(",");
            }
            out.print(normHiveIdentifier(col.getName()) + " " + hiveType(col.getType()) + "\n");
        }

        out.print(")" + "\n");
        out.print("ROW FORMAT DELIMITED FIELDS TERMINATED BY ','" + "\n");
        out.print("STORED AS TEXTFILE" + ";\n");
        out.print("\n");
    }
}
 
Example 2
Source File: TableGenConfig.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
public TableGenConfig(TableDesc table, ModelDataGenerator modelGen) throws IOException {
    String dataGen = table.getDataGen();
    if (dataGen == null && modelGen.existsInStore(table) == false) {
        dataGen = "";
    }
    
    if (dataGen == null || "no".equals(dataGen) || "false".equals(dataGen) || "skip".equals(dataGen))
        return;
    
    if (table.isView())
        return;
    
    needGen = true;
    
    Map<String, String> config = Util.parseEqualCommaPairs(dataGen, "rows");
    
    // config.rows is either a multiplier (0,1] or an absolute row number
    rows = Util.parseDouble(config, "rows", modelGen.getModle().isFactTable(table.getIdentity()) ? 1.0 : 20);
}
 
Example 3
Source File: ModelDataGenerator.java    From kylin with Apache License 2.0 6 votes vote down vote up
private void generateCreateTableDDL(Set<TableDesc> tables, PrintWriter out) {
    for (TableDesc t : tables) {
        if (t.isView())
            continue;

        out.print("DROP TABLE IF EXISTS " + normHiveIdentifier(t.getIdentity()) + ";\n");

        out.print("CREATE TABLE " + normHiveIdentifier(t.getIdentity()) + "(" + "\n");

        for (int i = 0; i < t.getColumns().length; i++) {
            ColumnDesc col = t.getColumns()[i];
            out.print("    ");
            if (i > 0) {
                out.print(",");
            }
            out.print(normHiveIdentifier(col.getName()) + " " + hiveType(col.getType()) + "\n");
        }

        out.print(")" + "\n");
        out.print("ROW FORMAT DELIMITED FIELDS TERMINATED BY ','" + "\n");
        out.print("STORED AS TEXTFILE" + ";\n");
        out.print("\n");
    }
}
 
Example 4
Source File: TableGenConfig.java    From kylin with Apache License 2.0 6 votes vote down vote up
public TableGenConfig(TableDesc table, ModelDataGenerator modelGen) throws IOException {
    String dataGen = table.getDataGen();
    if (dataGen == null && modelGen.existsInStore(table) == false) {
        dataGen = "";
    }
    
    if (dataGen == null || "no".equals(dataGen) || "false".equals(dataGen) || "skip".equals(dataGen))
        return;
    
    if (table.isView())
        return;
    
    needGen = true;
    
    Map<String, String> config = Util.parseEqualCommaPairs(dataGen, "rows");
    
    // config.rows is either a multiplier (0,1] or an absolute row number
    rows = Util.parseDouble(config, "rows", modelGen.getModle().isFactTable(table.getIdentity()) ? 1.0 : 20);
}
 
Example 5
Source File: HiveInputBase.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
protected static ShellExecutable createLookupHiveViewMaterializationStep(String hiveInitStatements,
        String jobWorkingDir, IJoinedFlatTableDesc flatDesc, List<String> intermediateTables, String uuid) {
    ShellExecutable step = new ShellExecutable();
    step.setName(ExecutableConstants.STEP_NAME_MATERIALIZE_HIVE_VIEW_IN_LOOKUP);

    KylinConfig kylinConfig = flatDesc.getSegment().getConfig();
    TableMetadataManager metadataManager = TableMetadataManager.getInstance(kylinConfig);
    final Set<TableDesc> lookupViewsTables = Sets.newHashSet();

    String prj = flatDesc.getDataModel().getProject();
    for (JoinTableDesc lookupDesc : flatDesc.getDataModel().getJoinTables()) {
        TableDesc tableDesc = metadataManager.getTableDesc(lookupDesc.getTable(), prj);
        if (lookupDesc.getKind() == DataModelDesc.TableKind.LOOKUP && tableDesc.isView()) {
            lookupViewsTables.add(tableDesc);
        }
    }

    if (lookupViewsTables.size() == 0) {
        return null;
    }

    HiveCmdBuilder hiveCmdBuilder = new HiveCmdBuilder();
    hiveCmdBuilder.overwriteHiveProps(kylinConfig.getHiveConfigOverride());
    hiveCmdBuilder.addStatement(hiveInitStatements);
    for (TableDesc lookUpTableDesc : lookupViewsTables) {
        String identity = FlatTableSqlQuoteUtils.quoteTableIdentity(lookUpTableDesc.getDatabase(), lookUpTableDesc.getName(), null);
        if (lookUpTableDesc.isView()) {
            String intermediate = lookUpTableDesc.getMaterializedName(uuid);
            String materializeViewHql = materializeViewHql(intermediate, identity, jobWorkingDir);
            hiveCmdBuilder.addStatement(materializeViewHql);
            intermediateTables.add(intermediate);
        }
    }

    step.setCmd(hiveCmdBuilder.build());
    return step;
}
 
Example 6
Source File: ModelDataGenerator.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
private void generateLoadDataDDL(Set<TableDesc> tables, PrintWriter out) {
    for (TableDesc t : tables) {
        if (t.isView()) {
            out.print("-- " + t.getIdentity() + " is view \n");
            continue;
        }

        out.print("LOAD DATA LOCAL INPATH '" + t.getIdentity() + ".csv' OVERWRITE INTO TABLE "
                + normHiveIdentifier(t.getIdentity()) + ";\n");
    }
}
 
Example 7
Source File: SnapshotCLI.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
private static void rebuild(String table, String overwriteUUID, String project) throws IOException {
    KylinConfig conf = KylinConfig.getInstanceFromEnv();
    TableMetadataManager metaMgr = TableMetadataManager.getInstance(conf);
    SnapshotManager snapshotMgr = SnapshotManager.getInstance(conf);

    TableDesc tableDesc = metaMgr.getTableDesc(table, project);
    if (tableDesc == null)
        throw new IllegalArgumentException("Not table found by " + table);

    if (tableDesc.isView())
        throw new IllegalArgumentException("Build snapshot of hive view \'" + table + "\' not supported.");

    SnapshotTable snapshot = snapshotMgr.rebuildSnapshot(SourceManager.createReadableTable(tableDesc, null), tableDesc, overwriteUUID);
    System.out.println("resource path updated: " + snapshot.getResourcePath());
}
 
Example 8
Source File: CubeService.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
public CubeInstance rebuildLookupSnapshot(CubeInstance cube, String segmentName, String lookupTable)
        throws IOException {
    aclEvaluate.checkProjectOperationPermission(cube);
    Message msg = MsgPicker.getMsg();
    TableDesc tableDesc = getTableManager().getTableDesc(lookupTable, cube.getProject());
    if (tableDesc.isView()) {
        throw new BadRequestException(
                String.format(Locale.ROOT, msg.getREBUILD_SNAPSHOT_OF_VIEW(), tableDesc.getName()));
    }
    CubeSegment seg = cube.getSegment(segmentName, SegmentStatusEnum.READY);
    getCubeManager().buildSnapshotTable(seg, lookupTable, null);

    return cube;
}
 
Example 9
Source File: JobService.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
public JobInstance submitLookupSnapshotJob(CubeInstance cube, String lookupTable, List<String> segmentIDs,
        String submitter) throws IOException {
    Message msg = MsgPicker.getMsg();
    TableDesc tableDesc = getTableManager().getTableDesc(lookupTable, cube.getProject());
    if (tableDesc.isView()) {
        throw new BadRequestException(
                String.format(Locale.ROOT, msg.getREBUILD_SNAPSHOT_OF_VIEW(), tableDesc.getName()));
    }
    LookupSnapshotBuildJob job = new LookupSnapshotJobBuilder(cube, lookupTable, segmentIDs, submitter).build();
    getExecutableManager().addJob(job);

    JobInstance jobInstance = getLookupSnapshotBuildJobInstance(job);
    return jobInstance;
}
 
Example 10
Source File: HiveInputBase.java    From kylin with Apache License 2.0 5 votes vote down vote up
protected static ShellExecutable createLookupHiveViewMaterializationStep(String hiveInitStatements, String jobWorkingDir, IJoinedFlatTableDesc flatDesc,
                                                                         List<String> intermediateTables, String uuid) {
    ShellExecutable step = new ShellExecutable();
    step.setName(ExecutableConstants.STEP_NAME_MATERIALIZE_HIVE_VIEW_IN_LOOKUP);

    KylinConfig kylinConfig = flatDesc.getSegment().getConfig();
    TableMetadataManager metadataManager = TableMetadataManager.getInstance(kylinConfig);
    final Set<TableDesc> lookupViewsTables = Sets.newHashSet();

    String prj = flatDesc.getDataModel().getProject();
    for (JoinTableDesc lookupDesc : flatDesc.getDataModel().getJoinTables()) {
        TableDesc tableDesc = metadataManager.getTableDesc(lookupDesc.getTable(), prj);
        if (lookupDesc.getKind() == DataModelDesc.TableKind.LOOKUP && tableDesc.isView()) {
            lookupViewsTables.add(tableDesc);
        }
    }

    if (lookupViewsTables.size() == 0) {
        return null;
    }

    HiveCmdBuilder hiveCmdBuilder = new HiveCmdBuilder();
    hiveCmdBuilder.overwriteHiveProps(kylinConfig.getHiveConfigOverride());
    hiveCmdBuilder.addStatement(hiveInitStatements);
    for (TableDesc lookUpTableDesc : lookupViewsTables) {
        String identity = FlatTableSqlQuoteUtils.quoteTableIdentity(lookUpTableDesc.getDatabase(), lookUpTableDesc.getName(), null);
        if (lookUpTableDesc.isView()) {
            String intermediate = lookUpTableDesc.getMaterializedName(uuid);
            String materializeViewHql = materializeViewHql(intermediate, identity, jobWorkingDir);
            hiveCmdBuilder.addStatement(materializeViewHql);
            intermediateTables.add(intermediate);
        }
    }

    step.setCmd(hiveCmdBuilder.build());
    return step;
}
 
Example 11
Source File: ModelDataGenerator.java    From kylin with Apache License 2.0 5 votes vote down vote up
private void generateLoadDataDDL(Set<TableDesc> tables, PrintWriter out) {
    for (TableDesc t : tables) {
        if (t.isView()) {
            out.print("-- " + t.getIdentity() + " is view \n");
            continue;
        }

        out.print("LOAD DATA LOCAL INPATH '" + t.getIdentity() + ".csv' OVERWRITE INTO TABLE "
                + normHiveIdentifier(t.getIdentity()) + ";\n");
    }
}
 
Example 12
Source File: SnapshotCLI.java    From kylin with Apache License 2.0 5 votes vote down vote up
private static void rebuild(String table, String overwriteUUID, String project) throws IOException {
    KylinConfig conf = KylinConfig.getInstanceFromEnv();
    TableMetadataManager metaMgr = TableMetadataManager.getInstance(conf);
    SnapshotManager snapshotMgr = SnapshotManager.getInstance(conf);

    TableDesc tableDesc = metaMgr.getTableDesc(table, project);
    if (tableDesc == null)
        throw new IllegalArgumentException("Not table found by " + table);

    if (tableDesc.isView())
        throw new IllegalArgumentException("Build snapshot of hive view \'" + table + "\' not supported.");

    SnapshotTable snapshot = snapshotMgr.rebuildSnapshot(SourceManager.createReadableTable(tableDesc, null), tableDesc, overwriteUUID);
    System.out.println("resource path updated: " + snapshot.getResourcePath());
}
 
Example 13
Source File: CubeService.java    From kylin with Apache License 2.0 5 votes vote down vote up
public CubeInstance rebuildLookupSnapshot(CubeInstance cube, String segmentName, String lookupTable)
        throws IOException {
    aclEvaluate.checkProjectOperationPermission(cube);
    Message msg = MsgPicker.getMsg();
    TableDesc tableDesc = getTableManager().getTableDesc(lookupTable, cube.getProject());
    if (tableDesc.isView()) {
        throw new BadRequestException(
                String.format(Locale.ROOT, msg.getREBUILD_SNAPSHOT_OF_VIEW(), tableDesc.getName()));
    }
    CubeSegment seg = cube.getSegment(segmentName, SegmentStatusEnum.READY);
    getCubeManager().buildSnapshotTable(seg, lookupTable, null);

    return cube;
}
 
Example 14
Source File: JobService.java    From kylin with Apache License 2.0 5 votes vote down vote up
public JobInstance submitLookupSnapshotJob(CubeInstance cube, String lookupTable, List<String> segmentIDs,
        String submitter) throws IOException {
    Message msg = MsgPicker.getMsg();
    TableDesc tableDesc = getTableManager().getTableDesc(lookupTable, cube.getProject());
    if (tableDesc.isView()) {
        throw new BadRequestException(
                String.format(Locale.ROOT, msg.getREBUILD_SNAPSHOT_OF_VIEW(), tableDesc.getName()));
    }
    LookupSnapshotBuildJob job = new LookupSnapshotJobBuilder(cube, lookupTable, segmentIDs, submitter).build();
    getExecutableManager().addJob(job);

    JobInstance jobInstance = getLookupSnapshotBuildJobInstance(job);
    return jobInstance;
}
 
Example 15
Source File: HiveInputBase.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
protected static String getTableNameForHCat(TableDesc table, String uuid) {
    String tableName = (table.isView()) ? table.getMaterializedName(uuid) : table.getName();
    String database = (table.isView()) ? KylinConfig.getInstanceFromEnv().getHiveDatabaseForIntermediateTable()
            : table.getDatabase();
    return String.format(Locale.ROOT, "%s.%s", database, tableName).toUpperCase(Locale.ROOT);
}
 
Example 16
Source File: HiveInputBase.java    From kylin with Apache License 2.0 4 votes vote down vote up
protected static String getTableNameForHCat(TableDesc table, String uuid) {
    String tableName = (table.isView()) ? table.getMaterializedName(uuid) : table.getName();
    String database = (table.isView()) ? KylinConfig.getInstanceFromEnv().getHiveDatabaseForIntermediateTable()
            : table.getDatabase();
    return String.format(Locale.ROOT, "%s.%s", database, tableName).toUpperCase(Locale.ROOT);
}