protected AbstractCubeTable(Table hiveTable) { this.name = hiveTable.getTableName().toLowerCase(); this.columns = hiveTable.getCols(); this.properties.putAll(hiveTable.getParameters()); this.weight = getWeight(getProperties(), getName()); }
@Override public void addColumns(Collection<FieldSchema> columns) { super.addColumns(columns); }
/** * Alters the weight of table * * @param weight Weight of the table. */ public void alterWeight(double weight) { this.weight = weight; this.addProperties(); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } AbstractCubeTable other = (AbstractCubeTable) obj; if (!this.getName().equalsIgnoreCase(other.getName())) { return false; } if (this.getColumns() == null) { if (other.getColumns() != null) { return false; } } else { if (!this.getColumns().equals(other.getColumns())) { return false; } } if (this.weight() != other.weight()) { return false; } return true; }
public void verifyStorageExists(AbstractCubeTable cdt, String storage) throws LensException { if (cdt.getStorages() == null || !cdt.getStorages().contains(storage)) { throw new LensException(LensCubeErrorCode.ENTITY_NOT_FOUND.getLensErrorInfo(), "storage " + storage + " for", cdt.getTableType().name().toLowerCase() + " " + cdt.getName()); } }
private Table createCubeHiveTable(AbstractCubeTable table) throws LensException { try { Table tbl = getClient().newTable(table.getName().toLowerCase()); tbl.setTableType(TableType.MANAGED_TABLE); tbl.getTTable().getSd().setCols(table.getColumns()); tbl.getTTable().getParameters().putAll(table.getProperties()); getClient().createTable(tbl); // do get to update cache getTable(tbl.getTableName()); return tbl; } catch (Exception e) { throw new LensException("Exception creating table", e); } }
public Optional<Date> getColumnStartTime(String column) { Date startTime = null; for (String key : getTable().getProperties().keySet()) { if (key.contains(MetastoreConstants.FACT_COL_START_TIME_PFX)) { String propCol = StringUtils.substringAfter(key, MetastoreConstants.FACT_COL_START_TIME_PFX); if (column.equals(propCol)) { startTime = MetastoreUtil.getDateFromProperty(getTable().getProperties().get(key), false, true); } } } return Optional.ofNullable(startTime); }
/** * * @param table table name * @param hiveTable hive table * @param cubeTable lens cube table * @return true if columns changed in alter * @throws LensException */ private boolean alterCubeTable(String table, Table hiveTable, AbstractCubeTable cubeTable) throws LensException { hiveTable.getParameters().putAll(cubeTable.getProperties()); boolean columnsChanged = !(hiveTable.getCols().equals(cubeTable.getColumns())); if (columnsChanged) { hiveTable.getTTable().getSd().setCols(cubeTable.getColumns()); } hiveTable.getTTable().getParameters().putAll(cubeTable.getProperties()); try { getClient().alterTable(table, hiveTable, null); } catch (Exception e) { throw new LensException(e); } return columnsChanged; }
public boolean containsColumnOfTable(String column, AbstractCubeTable table) { for (TableRelationship edge : edges) { if ((table.equals(edge.getFromTable()) && column.equals(edge.getFromColumn())) || table.equals(edge.getToTable()) && column.equals(edge.getToColumn())) { return true; } } return false; }
protected void addProperties() { properties.put(MetastoreConstants.TABLE_TYPE_KEY, getTableType().name()); properties.put(MetastoreUtil.getCubeTableWeightKey(name), String.valueOf(weight())); }
@Override public void alterColumn(FieldSchema column) { super.alterColumn(column); }
public Set<String> getAllFieldNames() { List<FieldSchema> fields = getColumns(); Set<String> columns = new HashSet<>(fields.size()); for (FieldSchema f : fields) { columns.add(f.getName().toLowerCase()); } return columns; }
private Table createCubeHiveTable(AbstractCubeTable table) throws LensException { try { Table tbl = getClient().newTable(table.getName().toLowerCase()); tbl.setTableType(TableType.MANAGED_TABLE); tbl.getTTable().getSd().setCols(table.getColumns()); tbl.getTTable().getParameters().putAll(table.getProperties()); getClient().createTable(tbl); // do get to update cache getTable(tbl.getTableName()); return tbl; } catch (Exception e) { throw new LensException("Exception creating table", e); } }
@Override public Optional<Date> getColumnEndTime(String column) { Date endTime = null; for (String key : getTable().getProperties().keySet()) { if (key.contains(MetastoreConstants.FACT_COL_END_TIME_PFX)) { String propCol = StringUtils.substringAfter(key, MetastoreConstants.FACT_COL_END_TIME_PFX); if (column.equals(propCol)) { endTime = MetastoreUtil.getDateFromProperty(getTable().getProperties().get(key), false, true); } } } return Optional.ofNullable(endTime); }
public void verifyStorageExists(AbstractCubeTable cdt, String storage) throws LensException { if (cdt.getStorages() == null || !cdt.getStorages().contains(storage)) { throw new LensException(LensCubeErrorCode.ENTITY_NOT_FOUND.getLensErrorInfo(), "storage " + storage + " for", cdt.getTableType().name().toLowerCase() + " " + cdt.getName()); } }
/** * * @param table table name * @param hiveTable hive table * @param cubeTable lens cube table * @return true if columns changed in alter * @throws LensException */ private boolean alterCubeTable(String table, Table hiveTable, AbstractCubeTable cubeTable) throws LensException { hiveTable.getParameters().putAll(cubeTable.getProperties()); boolean columnsChanged = !(hiveTable.getCols().equals(cubeTable.getColumns())); if (columnsChanged) { hiveTable.getTTable().getSd().setCols(cubeTable.getColumns()); } hiveTable.getTTable().getParameters().putAll(cubeTable.getProperties()); try { getClient().alterTable(table, hiveTable, null); } catch (Exception e) { throw new LensException(e); } return columnsChanged; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } AbstractCubeTable other = (AbstractCubeTable) obj; if (!this.getName().equalsIgnoreCase(other.getName())) { return false; } if (this.getColumns() == null) { if (other.getColumns() != null) { return false; } } else { if (!this.getColumns().equals(other.getColumns())) { return false; } } if (this.weight() != other.weight()) { return false; } return true; }
public boolean containsColumnOfTable(String column, AbstractCubeTable table) { for (TableRelationship edge : edges) { if ((table.equals(edge.getFromTable()) && column.equals(edge.getFromColumn())) || table.equals(edge.getToTable()) && column.equals(edge.getToColumn())) { return true; } } return false; }