Skip to content

Commit 0e5f5fb

Browse files
committed
add hasLabels property
allowing for there to not be labels at all will make things quite a bit faster I think
1 parent 0d5c4cb commit 0e5f5fb

File tree

5 files changed

+47
-13
lines changed

5 files changed

+47
-13
lines changed

CommonData/column.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void Column::dbLoad(int id, bool getValues)
7171
Json::Value emptyVals;
7272
int dropLevelsTypeInt = static_cast<int>(_dropLevels);
7373

74-
db().columnGetBasicInfo( _id, _name, _title, _description, _type, _revision, emptyVals, _autoSortByValue, dropLevelsTypeInt);
74+
db().columnGetBasicInfo( _id, _name, _title, _description, _type, _revision, emptyVals, _autoSortByValue, dropLevelsTypeInt, _hasLabels);
7575
db().columnGetComputedInfo( _id, _analysisId, _invalidated, _codeType, _rCode, _error, _constructorJson, _computeFilter);
7676

7777
try { _dropLevels = dropLevelsType(dropLevelsTypeInt); } catch(...){}
@@ -581,7 +581,7 @@ columnType Column::setValues(size_t rows, const std::function<std::string(size_t
581581

582582
//Weve already made sure we have only 1 label per value and display combo, because otherwise this will get too complicated
583583

584-
intset ints; // to suggest whether this is a scalar or not we need to know whether we have more than treshold ints or not.
584+
intset ints; // to suggest whether this is a scalar or not we need to know whether we have more than threshold ints or not.
585585
int tmpInt;
586586
double tmpDbl;
587587

@@ -2725,3 +2725,14 @@ int Column::filteredOut() const
27252725
}
27262726

27272727

2728+
2729+
void Column::setHasLabels(bool haveLabels)
2730+
{
2731+
if(haveLabels == _hasLabels)
2732+
return;
2733+
2734+
2735+
throw std::runtime_exception("Implement me!");
2736+
2737+
emit hasLabelsChanged();
2738+
}

CommonData/column.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@ class Column : public DataSetBaseNode
4343
{
4444
Q_OBJECT
4545

46-
Q_PROPERTY(QString name READ nameQ WRITE setNameQ NOTIFY nameChanged )
47-
Q_PROPERTY(QString title READ titleQ WRITE setTitleQ NOTIFY titleChanged )
48-
Q_PROPERTY(QString rcode READ rCodeQ WRITE setRCodeQ NOTIFY rCodeChanged )
46+
Q_PROPERTY(QString name READ nameQ WRITE setNameQ NOTIFY nameChanged )
47+
Q_PROPERTY(QString title READ titleQ WRITE setTitleQ NOTIFY titleChanged )
48+
Q_PROPERTY(QString rcode READ rCodeQ WRITE setRCodeQ NOTIFY rCodeChanged )
4949
Q_PROPERTY(columnType colType READ type WRITE setType NOTIFY columnTypeChanged )
50-
Q_PROPERTY(computedColumnType codeType READ codeType WRITE setCodeType NOTIFY codeTypeChanged )
50+
Q_PROPERTY(computedColumnType codeType READ codeType WRITE setCodeType NOTIFY codeTypeChanged )
51+
Q_PROPERTY(bool hasLabels READ hasLabels WRITE setHasLabels NOTIFY hasLabelsChanged )
5152

5253

5354
friend DatabaseInterface;
@@ -93,6 +94,7 @@ class Column : public DataSetBaseNode
9394
bool setNameQ( const QString & name );
9495
void setTitle( const std::string & title );
9596
void setTitleQ( const QString & title );
97+
void setHasLabels( bool haveLabels );
9698
bool setRCode( const std::string & rCode );
9799
bool setRCodeQ( const QString & rCode );
98100
bool setError( const std::string & error );
@@ -134,6 +136,7 @@ class Column : public DataSetBaseNode
134136
bool shouldDropLevels() const { return _dropLevels != dropLevelsType::keep; }
135137
bool invalidated() const { return _invalidated; }
136138
bool autoSortByValue() const { return _autoSortByValue; }
139+
bool hasLabels() const { return _hasLabels; }
137140
computedColumnType codeType() const { return _codeType; }
138141
const std::string & name() const { return _name; }
139142
const QString nameQ() const;
@@ -305,6 +308,7 @@ class Column : public DataSetBaseNode
305308
void nameChanged();
306309
void titleChanged();
307310
void rCodeChanged();
311+
void hasLabelsChanged();
308312
void descriptionChanged();
309313
void codeTypeChanged();
310314

@@ -320,7 +324,8 @@ class Column : public DataSetBaseNode
320324
int _nonFilteredNumericsCount = -1;
321325
bool _invalidated = false,
322326
_autoSortByValue,
323-
_hasShadows = false;
327+
_hasShadows = false,
328+
_hasLabels = false;
324329
dropLevelsType _dropLevels = dropLevelsType::noChoice;
325330
computedColumnType _codeType = computedColumnType::notComputed;
326331
std::string _name,
@@ -330,7 +335,9 @@ class Column : public DataSetBaseNode
330335
_rCode,
331336
_computeFilter = "DEFAULT_FILTER";
332337
Json::Value _constructorJson = Json::objectValue;
333-
intvec _ints;
338+
intvec _ints; ///For when there are labels
339+
stringvec _strs; ///For when there are no labels
340+
doublevec _dbls; ///For when there are no labels
334341
stringset _dependsOnColumns;
335342
std::map<int, Label*> _labelByIntsIdMap,
336343
_labelByNonEmptyIndex;

CommonData/databaseinterface.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ void DatabaseInterface::upgradeDBFromVersion(Version originalVersion)
8888

8989
if(!tableHasColumn("Filters", "invalidated"))
9090
runStatements("ALTER TABLE Filters ADD COLUMN invalidated INT;");
91+
92+
if(!tableHasColumn("Columns", "hasLabels"))
93+
runStatements("ALTER TABLE Columns ADD COLUMN hasLabels INT DEFAULT 0;");
9194
}
9295

9396
transactionWriteEnd();
@@ -1136,6 +1139,16 @@ void DatabaseInterface::columnSetAutoSort(int columnId, bool sort)
11361139
});
11371140
}
11381141

1142+
void DatabaseInterface::columnSetHasLabels(int columnId, bool hasLabels)
1143+
{
1144+
JASPTIMER_SCOPE(DatabaseInterface::columnSetHasLabels);
1145+
runStatements("UPDATE Columns SET hasLabels=? WHERE id=?;", [&](sqlite3_stmt * stmt)
1146+
{
1147+
sqlite3_bind_int(stmt, 1, hasLabels);
1148+
sqlite3_bind_int(stmt, 2, columnId);
1149+
});
1150+
}
1151+
11391152
void DatabaseInterface::columnSetInvalidated(int columnId, bool invalidated)
11401153
{
11411154
JASPTIMER_SCOPE(DatabaseInterface::columnSetInvalidated);
@@ -1261,7 +1274,7 @@ void DatabaseInterface::columnSetComputedInfo(int columnId, int analysisId, bool
12611274
});
12621275
}
12631276

1264-
void DatabaseInterface::columnGetBasicInfo(int columnId, std::string &name, std::string &title, std::string &description, columnType &colType, int & revision, Json::Value & emptyValuesJson, bool & autoSort, int & dropLevels)
1277+
void DatabaseInterface::columnGetBasicInfo(int columnId, std::string &name, std::string &title, std::string &description, columnType &colType, int & revision, Json::Value & emptyValuesJson, bool & autoSort, int & dropLevels, bool & hasLabels)
12651278
{
12661279
JASPTIMER_SCOPE(DatabaseInterface::columnGetBasicInfo);
12671280

@@ -1276,7 +1289,7 @@ void DatabaseInterface::columnGetBasicInfo(int columnId, std::string &name, std:
12761289
{
12771290
int colCount = sqlite3_column_count(stmt);
12781291

1279-
assert(colCount == 8);
1292+
assert(colCount == 9);
12801293
name = _wrap_sqlite3_column_text(stmt, 0);
12811294
title = _wrap_sqlite3_column_text(stmt, 1);
12821295
description = _wrap_sqlite3_column_text(stmt, 2);
@@ -1285,14 +1298,15 @@ void DatabaseInterface::columnGetBasicInfo(int columnId, std::string &name, std:
12851298
std::string emptyValuesStr = _wrap_sqlite3_column_text(stmt, 5);
12861299
autoSort = sqlite3_column_int( stmt, 6);
12871300
dropLevels = sqlite3_column_int( stmt, 7);
1301+
hasLabels = sqlite3_column_int( stmt, 8);
12881302

12891303

12901304
colType = colTypeStr.empty() ? columnType::unknown : columnTypeFromString(colTypeStr);
12911305

12921306
Json::Reader().parse(emptyValuesStr, emptyValuesJson);
12931307
};
12941308

1295-
runStatements("SELECT name, title, description, columnType, revision, emptyValuesJson, autoSortByValue, dropLevels FROM Columns WHERE id = ?;", prepare, processRow);
1309+
runStatements("SELECT name, title, description, columnType, revision, emptyValuesJson, autoSortByValue, dropLevels, hasLabels FROM Columns WHERE id = ?;", prepare, processRow);
12961310
}
12971311

12981312

CommonData/databaseinterface.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,16 @@ class DatabaseInterface
141141
int columnGetDataSetId( int columnId);
142142
void columnDelete( int columnId, bool cleanUpRest = true); ///< Also makes sure indices stay as contiguous and correct as before. disable cleanUpRest to just clear from Columns
143143
void columnSetType( int columnId, columnType colType);
144-
void columnSetAutoSort( int columnId, bool sort);
145144
void columnSetInvalidated( int columnId, bool invalidated);
145+
void columnSetAutoSort( int columnId, bool sort);
146+
void columnSetHasLabels( int columnId, bool hasLabels);
146147
void columnSetDropLevels( int columnId, int dropLevels);
147148
void columnSetName( int columnId, const std::string & name);
148149
void columnSetTitle( int columnId, const std::string & title);
149150
void columnSetEmptyVals( int columnId, const std::string & emptyValsJson);
150151
void columnSetDescription( int columnId, const std::string & description);
151152
void columnSetComputeFilter( int columnId, const std::string & computeFilter);
152-
void columnGetBasicInfo( int columnId, std::string & name, std::string & title, std::string & description, columnType & colType, int & revision, Json::Value & emptyValuesJson, bool & autoSort, int & dropLevels);
153+
void columnGetBasicInfo( int columnId, std::string & name, std::string & title, std::string & description, columnType & colType, int & revision, Json::Value & emptyValuesJson, bool & autoSort, int & dropLevels, bool & hasLabels);
153154
void columnSetComputedInfo( int columnId, int analysisId, bool invalidated, computedColumnType codeType, const std::string & rCode, const std::string & error, const std::string & constructorJson, const std::string & computeFilter);
154155
void columnGetComputedInfo( int columnId, int &analysisId, bool & invalidated, computedColumnType & codeType, std::string & rCode, std::string & error, Json::Value & constructorJson, std::string & computeFilter);
155156
void columnSetValues( int columnId, const intvec & ints);

CommonData/internalDbDefinition.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ CREATE TABLE Columns
4040
autoSortByValue INT,
4141
dropLevels INT,
4242
invalidated INT NULL,
43+
hasLabels INT DEFAULT 0,
4344
codeType TEXT NULL,
4445
rCode TEXT NULL,
4546
error TEXT NULL,

0 commit comments

Comments
 (0)